What file formats can PDF WebViewer display?

Skip to first unread message

Ryan - PDFNet Developer

Oct 12, 2016, 6:26:08 PM10/12/16
to pdfnet-w...@googlegroups.com

I know PDF WebViewer (PDFNetJS) can display PDF files directly, but are there other formats supported client side?


Yes, there are a number of image formats supported. Here is the breakdown.

Simply pass the image URL to WebViewer initialDoc constructor parameter, or to WebViewer.loadDocument.

If your URL does not have a proper image extension, then you can do the following.
myWebViewer.loadDocument("mydomain/generic_url_to_image", {filename: "input.png"})

This works with both PDFNetJS Lean and Full editions.

TIFF, GIF, JP2 or Multiple PNG/JPG.
This is possible, using PDFNetJS Full edition, which does not come with the regular WebViewer download.

Using PDFNetJS Full you would follow the AddImage sample code to construct a PDF with the image(s) in it.

Another option, which you can use with the PDFNetJS Lean version (not the full version) is to use a 3rd party library that can convert the image format to HTML5 canvas, then from the HTML5 canvas you can get a PNG. For instance, for TIFF files the following library will load it into a HTML5 canvas

Irfan Majeed

Feb 7, 2018, 12:47:22 PM2/7/18
to PDFTron WebViewer
i tried to use this method but it gives error signature is wrong below the code for js function.jsfiddle.net/3v94uc9b 

Irfan Majeed

Feb 7, 2018, 12:47:28 PM2/7/18
to PDFTron WebViewer

Matt Parizeau

Feb 8, 2018, 3:04:19 PM2/8/18
to PDFTron WebViewer

When loading images directly you should set the documentType to 'pdf' instead of the image extension. This is a bit confusing but it's because behind the scenes PDF and images use the same rendering technology. You can see the valid values for the documentType option here https://www.pdftron.com/webviewer/demo/doc/symbols/PDFTron.WebViewer.html#Options__anchor.

Matt Parizeau
Software Developer
PDFTron Systems Inc.
Reply all
Reply to author
0 new messages