PDFtron failing to load and download PNG and JPEG images

WebViewer Version:

Do you have an issue with a specific file(s)?
Yes, Having trouble with PNG and JPEG files that are uploaded into webviewer via a path or uploaded into the PDFTron demo from my local machine. PDFs seem to work fine.

Can you reproduce using one of our samples or online demos?
Yes. Reproducible with the official PDFTron demo by loading almost any png or jpeg file. Results in a “Document loading failed. Please try another file, or visit the File Gallery to choose from our samples” error message.

Are you using the WebViewer server?
No

Does the issue only happen on certain browsers?
No

Is your issue related to a front-end framework?
No

Is your issue related to annotations?
No

Please give a brief summary of your issue:
(Think of this as an email subject)
Webviewer not displaying or downloading PNG or JPEG files

Please describe your issue and provide steps to reproduce it:
(The more descriptive your answer, the faster we are able to help you)
Hello, I’m having trouble with PNG or JPEG formats loading or downloading into the PDFtron webviewer. When trying to call the loadDocument method I am getting a Uncaught (in promise) undefined which points to t.bx @ webviewer-core.min.js:1 or Qa.bx @ webviewer-core.min.js:322. I have tried a number of different ways but the files just seem to error out loading. There is nothing too fancy about the document loading and it works great for PDFs. I am even passing in the extension.

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

Hello, I’m Ron, an automated tech support bot :robot:

While you wait for one of our customer support representatives to get back to you, please check out some of these documentation pages:

Guides:APIs:Forums:

Hello,

Thanks for reporting this issue! I can reproduce the issue and there appears to be a type mismatch. We will try to address the issue in a nightly stable build ASAP.

Thanks and sorry for the inconvenience!

The issue should be fixed in the nightly stable build for tomorrow (July 12th): PDFTron Systems Inc. | Nightly

Thanks Andy. Appreciate the update

Just tested out the latest build and it appears that PNG and JPEG file loading and downloading is still not working correctly. When attempting to load PNGs or JPEG files in the official PDFTron demo from my local machine there is a new error of:
[object%20File]:1 GET https://www.pdftron.com/webviewer/demo/res/webviewer/8.6.1/ui/[object%20File] 404

In addition it appears in my setup (v8.6.0) the PNG files are actually loading into webviewer (you can see them) but failing to download via the instance.downloadPdf method. Using the work around of doc.getFileData({...}) as suggested here seems to work.

Sorry about that! The fix seems to have made it into the July 13th build. Please try that one!

Just checked out the official demo again and its still not loading png or jpeg files. Still getting the same https://www.pdftron.com/webviewer/demo/res/webviewer/8.6.1/ui/[object%20File] 404 error as yesterday. Can you provide any insight into this? Thanks for your continued updates!

You cannot check the live demos as they tend to use the original release. You have to use the nightly stable build from the link I provided.

Possibly related, the getDocumentCompletePromise() returns undefined when you have loaded an image into the PDFTron Webviewer. This causes some major issues when you are attempting to download a document that is programmatically loaded into the Webviewer (we have to do this so that we can apply & flatten xfdf annotation data)

This has been broken since version 8.5.0 and is still broken in the nightly stable builds

Example code

docViewer
  .getDocument()
  .getDocumentCompletePromise()
  .then(() => {
    return instance.downloadPdf({
      filename: exhibit.attributes.name,
      includeAnnotations: true,
      flatten: true,
    });
  });

Hello bmathis,

It looks like the promise is not meant to return anything and the documentation is just misleading. The function has been returning the same even before 8.3 (tested in 7.3.4 and 6.3.6).

We will update the documentation to reflect the function. Thanks for reporting the issue!

@Andy_Huang

It looks like the promise is not meant to return anything and the documentation is just misleading. The function has been returning the same even before 8.3 (tested in 7.3.4 and 6.3.6).

This isn’t the issue. The function getDocumentCompletePromise() returns a Promise if you load anything into PDFTron that is not an image.

If you have loaded an image type document into the WebViewer then getDocumentCompletePromise() returns undefined. It will not return a Promise.

It looks like this issue was introduced with the image optimization update that came about in 8.5. Using loadAsPDF: true in the constructor should work around this issue.

The issue seems somewhat related to the original issue but it isn’t quite the cause. As such, this issue will have to be addressed separately and we will look into it!

Thanks for reporting and issue and sorry for the inconvenience!

It looks like this is still not fixed in the most recent 8.7.0 build. Images still fail to download when calling instance.downloadPdf. Using the blob based approach as seen in the updated guide Saving a document with JavaScript works but the instance.downloadPdf and instance.UI.downloadPdf do not seem to work with png and other image formats.

Hm, I don’t seem to be getting any 404’s, but I was getting an error about the download being rejected due to it not being a PDF. I have since corrected the issue, and it should be available in the nightly stable build for tomorrow (Aug 3rd PST).

Please give it a try and let me know how it goes!