Some test text!

menu
Info dictionarykeyboard_arrow_down

Information dictionary: adding custom data to a PDF using JavaScript

Only available with the Full API

To add custom data to an existing document.

<html>
  <script src="../lib/core/CoreControls.js"></script>
  <script src="../lib/core/pdf/PDFNet.js"></script>
  <script>
    (async function() {
      CoreControls.setWorkerPath('../lib/core');

      // In case you have PDFDoc you can always access
      // SDF/Cos document using PDFDoc.GetSDFDoc() method
      const pdf_doc = await PDFNet.PDFDoc.createFromURL(filename);
      const doc =  await pdf_doc.getSDFDoc();
      const trailer = await doc.getTrailer(); // Get the trailer

      // Create an Info dictionary
      const info = await trailer.putDict('Info');
      info.putString('Producer', 'PDFTron PDFNet');

      // Create a custom inline dictionary within Infor dictionary
      const customDict = await info.putDict('My Direct Dict');
      customDict.putNumber('My Number', 100); 
    })()
  </script>
</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.

Get the answers you need: Support

close

Free Trial

Get unlimited trial usage of PDFTron SDK to bring accurate, reliable, and fast document processing capabilities to any application or workflow.

Select a platform to get started with your free trial.

Unlimited usage. No email address required.

Join our live demo to learn about use cases & capabilities for WebViewer

Learn more
close