Convert PDF to Image (JPEG, PNG, etc)

139 views
Skip to first unread message

ar m

unread,
Mar 12, 2021, 6:28:04 PM3/12/21
to PDFTron WebViewer
Hi,

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.

Regards,

Matt Parizeau

unread,
Mar 15, 2021, 12:31:44 PM3/15/21
to PDFTron WebViewer
Hi,

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". 


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 https://www.pdftron.com/documentation/web/guides/lower-level-doc-create-pdf/

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.

ar m

unread,
Mar 19, 2021, 12:22:47 PM3/19/21
to PDFTron WebViewer
Thanks. It was easy!
Reply all
Reply to author
Forward
0 new messages