Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Editing javascript in a pdf with .net

Is it possible to edit the javascript of a pdf document with .net?

I've looked at the Acrobat SDK, but without much luck. It looks like you can retrieve values from forms etc. but not edit the document.

Am I way off track? Is this even possible?

I've tried iTextSharp, but since the pdf contains form fields, the fields are lost when I save the pdf.

Any suggestions?

like image 618
Christian Payne Avatar asked Feb 25 '23 23:02

Christian Payne


1 Answers

Well, apparently you can with iTextSharp:

        Document document = new Document(PageSize.A4, 50, 50, 50, 50);

        PdfReader reader = new PdfReader(@"Source.pdf");
        FileStream output = new FileStream(@"Destination.pdf", FileMode.Create);

        PdfStamper pdfStamper = new PdfStamper(reader, output, '\0', true);               
        pdfStamper.JavaScript = "app.alert(\"Hello world!\");";

        pdfStamper.FormFlattening = false;
        pdfStamper.Close();
        reader.Close();

(This question helped)

like image 53
Christian Payne Avatar answered Mar 01 '23 10:03

Christian Payne