javascriptpdfitextlivecycle

Cannot access PDF doc pages/events from iTextSharp with JavaScript


Ideally, I am trying to trigger an event in a PDF, using iTextSharp. Failing that, I would like to know if I can trigger a function.

Basically, I'm just trying to get a handle of the document through javascript.

This works in the PDF

(Using LiveCycle):

eApp.Page1.FormPurpose_PolicyNumber::click - 

(JavaScript, client)

this.rawValue = "hello";

From C# I can't get a handle on the doc, eApp in this case.

var reader = new PdfReader(pdfFileStream);
var writer = new PdfStamper(reader, outputStream);

THIS WORKS:(app object)

PdfAction js =
    PdfAction.JavaScript(
        "app.alert('hello');",
        writer.Writer);

writer.Writer.AddJavaScript(js);

THIS DOES NOT:

PdfAction js =
    PdfAction.JavaScript(
        "eApp.Page1.FormPurpose_PolicyNumber.execEvent('click');",
        writer.Writer);

writer.Writer.AddJavaScript(js);

Also doesn't work:

PdfAction js =
    PdfAction.JavaScript(
        "eApp.Page1.FormPurpose_PolicyNumber.rawValue= 'hello'",
        writer.Writer);

writer.Writer.AddJavaScript(js);

I have looked for the answer high and low, but have not been able to find it, yes there are similar questions, but either they are not answered or are very different than what I'm doing.


Solution

  • According to your latest comment - that won't work. iTextSharp will only add some scripts into a document. And that script will be started in some client app, like Adobe Reader. It will not execte any scripts inside of your document. Suppose in your case it will be easier to do whatewer you want with document using c# and than save it with form flattening set to true.