Convert PDF to Image (JPEG, PNG, etc)


I want to convert PDF to Image. I am trying to do it in plain javascript without using any server. is it possible?

I tried using PDFNet.PDFDraw.exportBuffer, but it says PDFNet.PDFDraw.exportBuffer is not a function.

Any Help would be appreciated.



Yes, you can definitely do this without using a server. It’ll probably be easier using the Document APIs instead of PDFNet APIs, and faster too because you don’t need to load the “full API”.

If you’re already using a viewer you can use code like this

Note that from a browser canvas object you can use the toDataURL or toBlob functions to get the image data

If you want to do it and you don’t have a WebViewer instance already you can first create a Document object in memory using CoreControls.createDocument

That doc object is the exact same as what you get from docViewer.getDocument() so then you can call doc.loadCanvasAsync to get the rendered page.

Let me know if you have any other questions about this.

Matt Parizeau
Software Developer
PDFTron Systems Inc.

Thanks. It was easy!