Q: We want to embed javascript inside a pdf.
In the faq is a small description but its refers to a PDF Reference
Manual that I don't find on your page.
So could you send me a simple example to embed javascript inside a
pdf?
Something like open a pdf and add an 'alert' to the document. C# would
be great.
-----
A: I assume that you are referring to the following FAQ:
http://www.pdftron.com/net/faq.html#js_embed
You can download the PDF Reference Manual using the following link:
http://www.pdftron.com/downloads/PDFReference16.pdf
For example:
PDFNet.Initialize();
PDFDoc pdfdoc = PDFDoc(@"c:\mypdf.pdf");
pdfdoc.InitSecurityHandler();
Obj root = pdfdoc.GetRoot();
Obj aa = root.PutDict("AA");
Obj ds = pdfdoc.CreateIndirectDict();
Obj ws = pdfdoc.CreateIndirectDict();
Obj dc = pdfdoc.CreateIndirectDict();
// See Table 8.47 in PDF Reference.
aa.Put("DS", ds); // Did Save Action
aa.Put("WS", ws); // Will Save Action
aa.Put("DC", dc); // Document Close Action
ds.PutName("S", "JavaScript");
ds.PutString("JS", "alert(' DidSave');");
ws.PutName("S", "JavaScript");
ws.Puttring("JS", "alert(' OnSave ');");
dc.PutName("S", "JavaScript");
dc.PutString("JS", "alert(' OnClose ');");
doc.Save(@"c:\mypdf_modified.pdf", SDFDoc.SaveOptions.e_linearized);
doc.Close();