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

I've looked at the [Acrobat SDK](http://sourceforge.net/projects/itextsharp/), 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](http://sourceforge.net/projects/itextsharp/), but since the pdf contains form fields, the fields are lost when I save the pdf.

Any suggestions?

Answer: 
Well, apparently you can with [iTextSharp](http://sourceforge.net/projects/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](https://stackoverflow.com/questions/209972/how-to-programmatically-inject-javascript-in-pdf-files) helped)
Sure, javascript of a PDF document can be edited.

I don't know how it can be done in other libraries but with [Docotic.Pdf](https://bitmiracle.com/pdf-library/) (I work for Bit Miracle) you can add/remove/edit javascript actions for controls, pages and document as a whole.

Here is a sample for setting and changing javascript action. The code assumes that document contain a button.

```
PdfDocument doc = new PdfDocument("document-with-button.pdf");
// assume that first widget is a button
PdfButton button = doc.Widgets[0] as PdfButton; 

// add javascript action for OnMouseEnter event
PdfJavaScriptAction action = doc.CreateJavaScriptAction("app.alert('OnMouseEnter JavaScript Action',3)");
button.OnMouseEnter = action;

// change javascript action for OnMouseEnter event
(button.OnMouseEnter as PdfJavaScriptAction).Script = "app.alert('Well, hello from OnMouseEnter JavaScript Action',3)";

doc.Save("output.pdf");

```