Question

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.

Était-ce utile?

La 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.

Autres conseils

In my case working solution is:

PdfReader reader = new PdfReader(this.pathToPDFTemplate);
...
PdfStamper stamper = new PdfStamper(reader, stream);
...
PdfAction action = PdfAction.JavaScript("this.xfa.form.form1.DesignArea.sfPart3.sfPart3_5.ck2.presence = 'hidden';", stamper.Writer);
stamper.Writer.SetAdditionalAction(PdfWriter.WILL_PRINT, action);
...

The trick is to use this.xfa.form. before your path to the field.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top