skip to Main Content

I have used PDFTron to update/edit PDF files. I have followed the documentation for opening the PDF file which came from server, but I am not sure how to save the edited PDF file with this SDK (PDFTron).

I have referred below links to save PDF, but did not succeed.
https://www.pdftron.com/documentation/ios/guides/features/forms/export-data/
https://www.pdftron.com/api/ios/Enums/PTSaveOptions.html

I want to send XFDF file formats to server.

PDFTron saves PDF with annotation automatically after some time interval, but I want it to be saved by save button press. I am stuck on this saving process.

I have below code to import annotation and I don’t know how to import this XFDF file and where do to get this XFDF file.

// Import annotations from XFDF to FDF
let fdf_doc: PTFDFDoc = PTFDFDoc.create(fromXFDF: xfdf_filename)

// Optionally read XFDF from a string
let fdf_doc: PTFDFDOc = PTFDFDoc.create(fromXFDF: xfdf_string)

// Merge FDF data into PDF doc
let doc: PTPDFDoc = PTPDFDoc(filepath: filename)
doc.fdfMerge(fdf_doc)

I don’t want it to be customisations by myself, I just want it to be saved by me on pressing button.

Below is my query

  1. How do I save the applied annotation on PDF by myself?

2

Answers


  1. Once you’ve applied changes to the document data you’ll probably want to do something with the updated PDF like letting the user download it or sending it back to your server.

    If you just want to let the user download the edited file then no extra changes are necessary as pressing the download button will save the modified PDF to the user’s computer.
    To add a custom save button, here is a code sample.

    If you want to get the modified PDF as an ArrayBuffer then you can use the
    getFileData function on Document.

    For example:

    WebViewer(...)
      .then(instance => {
        const { documentViewer, annotationManager } = instance.Core;
    
        documentViewer.addEventListener('documentLoaded', async () => {
          const doc = documentViewer.getDocument();
          const xfdfString = await annotationManager.exportAnnotations();
          const options = { xfdfString };
          const data = await doc.getFileData(options);
          const arr = new Uint8Array(data);
          const blob = new Blob([arr], { type: 'application/pdf' });
          // upload blob to your server
        });
      });
    
    Login or Signup to reply.
  2. I have followed the documentation for opening the PDF file which came from server

    There are a few ways to do this – could you share which API you are using?

    The main point of your question seems to be how to save the PDF via a button press (after you’ve merged in XFDF annotation data). Is this the case?

    You can control where a remote document is shared by implementing the relevant delegate methods, likely specifically https://www.pdftron.com/api/ios/Protocols/PTDocumentControllerDelegate.html#/c:objc(pl)PTDocumentControllerDelegate(im)documentController:destinationURLForDocumentAtURL:

    You can then save the document using this method:

    https://www.pdftron.com/api/ios/Classes/PTDocumentBaseViewController.html#/c:objc(cs)PTDocumentBaseViewController(im)saveDocument:completionHandler:

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search