pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David VanderMolen <d_vandermolen...@yahoo.com>
Subject document level javascript insertion
Date Tue, 05 Mar 2013 23:42:00 GMT
PDFBox 1.7

I'm trying to insert some javascript into a PDF at the document level, not tied to an action. 
I can't quite figure out how to do the insert and get the xref to set in the PDJavascriptNameTreeNode.


PDDocument doc = PDDocument.load(inputStream);
PDDocumentCatalog catalog=doc.getDocumentCatalog();
PDDocumentNameDictionary names=catalog.getNames();

PDJavascriptNameTreeNode ntree=new PDJavascriptNameTreeNode();
Map<String,PDTextStream> map=new HashMap<String,PDTextStream>();
PDActionJavaScript js1= new PDActionJavaScript("omitted");

//need to insert the javascript somewhere and get its xref
String xref="17 0 R";


map.put("com.adobe.acrobat.SharedReview.Register", new PDTextStream(xref));
ntree.setNames(map);
names.setJavascript(ntree);
catalog.setNames(names);

The desired output looks like this:

6 0 obj
<< /JavaScript 11 0 R >>
endobj
11 0 obj
<< /Names [ (com.adobe.acrobat.SharedReview.Register) 17 0 R  ] >>
endobj
17 0 obj
<< /JS 26 0 R /S /JavaScript >>
endobj
26 0 obj
<< /Length 7 >>
stream
omittedendstream
endobj

Thank you for the assistance. 

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message