PDF with non-standard attachments

WebViewer Version: 8.1.0

Do you have an issue with a specific file(s)?

Yes, attached the WithAttachment.pdf and tooBig.pdf below.

Please give a brief summary of your issue:
(Think of this as an email subject)
Cannot determine if the PDF with non-standard attachments has attachments.

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

We need to determine if the uploaded files in the system have attachments. To do that we search for the EmbeddedFiles node as shown below:

const pdfHasAttachments = await PDFNet.NameTree.find(doc, 'EmbeddedFiles');

It works for most of the PDFs, however there are some PDFs that have attachments (we can view them in tools like Adobe Acrobat) but without the EmbeddedFiles node. We analyzed the PDF files using PDF explorer tool and found that most PDF files with attachments have EmbeddedFiles node:

WithAttachment.pdf (62.1 KB)

The example file with attachments but without EmbeddedFiles node:

The tooBig.pdf file exceeds the allowed 4MB limit so I’ve attached the link to the file: Easyupload.io - Upload files for free and transfer big files easily.

The problem we have is that the second file tooBig.pdf is not recognized as a PDF file with attachments.

Is there a way to determine if the files like the tooBig.pdf have attachments?

Hello,

Thank you for contacting us about WebViewer and for the detail description. How was the “tooBig.pdf” document generated? The “name tree” is a set of key and value pairs that can used to conveniencely find data in a document. The keys can be anything but normally attachments uses EmbeddedFiles and AP is used for annotation appearances.

For the “tooBig.pdf” document, since it can’t use the name tree to quickly get the file attachment, you’ll need to iterate over the annotations to see if there is a file attachment. You can do something like the following

const pageCount = await doc.getPageCount();

for (let currentPage = 1; currentPage <= pageCount; currentPage++) {
  const page = await doc.getPage(currentPage);
  const annots = await page.getAnnots();
    for (let currIndex = 0; ; currIndex++) {
      const annotation = await page.getAnnot(currIndex);
      if (!annotation) {
        break;
      }

      const typeID = await annotation.getType();
        if (typeID === PDFNet.Annot.Type.e_FileAttachment) {
          console.log('attachment found');
          // break;
       }
    }
}

The above code is assuming you are using our low level API (this doesn’t require loading the document in WebViewer), if you are loading the document in WebViewer, you can use the annotationManager to get a list of all the annotations

Let me know if the above helps or if you want me to clarify anything

Best Regards,

Andrew Yip
Software Developer
PDFTron Systems, Inc.
www.pdftron.com