How to Download PDF file With Annotation With out using Webviewer in Salesforce

Product: PDFTron Library

Product Version: Trial version

Please give a brief summary of your issue:
(Think of this as an email subject)
The problem/Issue I am facing in our Salesforce Application is to Implement the Download PDF with Annotation without using WebViewer.

Can you please provide me the info/steps to Implement the Download PDF with Annotation in Salesforce Application with Full API without using WebViewer?

Because the requirement is to download the PDF with Annotation with out loading the WebViewer.
Outside of the PDFTron Web-Viewer on Click on the button I need to download the PDF file with Annotation

Please help me out to resolve this

Please describe your issue and provide steps to reproduce it:
(The more descriptive your answer, the faster we are able to help you)

Please provide a link to a minimal sample where the issue is reproducible:


Thank you for posting to the PDFTron community!

Can you provide some additional context for us to better understand your question - when you say Download PDF, is this an attached file on a record? Where are the annotations coming from? Could you maybe walk us through your user flow? Thanks!


I wanted to answer your question of how to save pdf with XFDF string included in PDF without using WebViewer UI.
Related APIs you need to use: Core.createDocument for loading PDF from URL, doc.getFileData for merging XFDF and creating PDF in raw format.

Here is an example:

This example file shows how to load core-controls

    <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" />
    <script src='../../../lib/samples/FileSaver.min.js'></script>
  <body style='padding: 0; margin: 0'>

    <script src="../../../lib/core/webviewer-core.min.js"></script>
    <script src='./index.js'></script>

The main JS file


const xfdfString = `<?xml version="1.0" encoding="UTF-8" ?><xfdf xmlns="" xml:space="preserve"><pdf-info xmlns="" version="2" import-version="4" /><fields /><annots><square page="0" rect="138.180,570.180,413.330,695.030" color="#E44234" flags="print" name="8ad6ceb1-aed3-726c-4862-14e42b33a219" title="Guest" subject="Rectangle" date="D:20220118114254-08'00'" creationdate="D:20220118114254-08'00'"/></annots><pages><defmtx matrix="1,0,0,-1,0,792" /></pages></xfdf>`

Core.createDocument('/blank.pdf').then(async (doc) => {
  const data = await doc.getFileData({
    // saves the document with annotations in it
  const arr = new Uint8Array(data);
  const blob = new Blob([arr], { type: 'application/pdf' });
  saveAs(blob, 'output.pdf');
}).catch(error => {

Hi Sardor,

Thank you for the reply.

The above solution you have provided is for the sales force application ?
If Yes →
Where to add the index.html files in sales force because it wont accept the html file which as head,
body and script tag

No, this is not specifically for Salesforce, but this general example of how you can do this. You can use examples to implement your own code.