Information dictionary: adding custom data to a PDF using JavaScript

To add custom data to an existing document.

1<html>
2 <script src="../lib/core/webviewer-core.min.js"></script>
3 <script src="../lib/core/pdf/PDFNet.js"></script>
4 <script>
5 (async function() {
6 Core.setWorkerPath('../lib/core');
7
8 // In case you have PDFDoc you can always access
9 // SDF/Cos document using PDFDoc.GetSDFDoc() method
10 const pdf_doc = await PDFNet.PDFDoc.createFromURL(filename);
11 const doc = await pdf_doc.getSDFDoc();
12 const trailer = await doc.getTrailer(); // Get the trailer
13
14 // Create an Info dictionary
15 const info = await trailer.putDict('Info');
16 info.putString('Producer', 'Apryse PDFNet');
17
18 // Create a custom inline dictionary within Infor dictionary
19 const customDict = await info.putDict('My Direct Dict');
20 customDict.putNumber('My Number', 100);
21 })()
22 </script>
23</html>

Cos/SDF low-level API to edit PDF files
Full code sample which illustrates how to use basic Cos/SDF API to edit an existing document.

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales
Add Custom Data to PDF Documents in JavaScript | Apryse documentation