2

I want to load an image file using the pdftron webviewer api.

For pdf files it's working fine but I want to load image files and add annotations to them.

In the user guide there is no information regarding working with images.

Graham
  • 7,431
  • 18
  • 59
  • 84

1 Answers1

3

Yes, WebViewer can do this out of the box.

There are a number of image formats supported. Here is the breakdown.

PNG, JPEG

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

If your URL does not have a proper file 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, BMP

You can utilize the browser's HTML5 canvas to load the images, and then generate PNG/JPG from the HTML5 canvas, and then pass the follow the instructions above.

JP2 or multiple images in one document.

Using PDFNetJS Full edition, which does not come with the standard WebViewer download, you have full control over PDF creation. PDFNetJS Full Download: http://pdftron.com/downloads/PDFNetJS.zip

Using PDFNetJS Full you would follow the AddImage sample code to construct a PDF with the image(s) in it. http://pdftron.com/webviewer/pdfnetjs/config.html#file=samples/PDFNet/AddImageTest/AddImageTest.js

Ryan
  • 2,473
  • 1
  • 11
  • 14
  • i tried to use this method but it gives error signature is wrong below the code for js function. https://jsfiddle.net/3v94uc9b/ – irfan majeed Feb 07 '18 at 03:48
  • 1
    The doctype variable should stay as PDF, regardless of the image type. So for example, initialDoc="mydomain.com/myfile.png" and docType="pdf" – Ryan Feb 07 '18 at 18:29
  • I would be glad to help, but to follow StackOverflow guidelines, please create a new question. – Ryan Feb 07 '18 at 23:29