简体   繁体   中英

Convert word and pdf document pages to jpg or png images

Looking for any client side support or module suggestion to convert word (and pdf) document pages to array of jpg or png images. I could not find any relevant npm module or service available.

For PDF files, in case you are using react.js for you website you can use the below npm module:- https://www.npmjs.com/package/react-pdf-to-image

More details can be found on this another stackoverflow thread:-
How to convert PDF to Image in ReactJS .

It uses pdf.js internally, so in case you are looking for vanilla Javascript implementation, check out this Github gist which shows the code snippet for using pdf.js to convert PDF to images using canvas.toDataURL('image/jpeg') method:-
https://gist.github.com/ichord/9808444

In case of word documents, there is an npm for react which can be used to display word documents:- https://github.com/Alcumus/react-doc-viewer#readme .

Or for vanilla Javascript you can use the below library to display word document in browser:- https://github.com/lalalic/docx2html

I think we can then convert the rendered doc file to image using canvas element using Javascript or npm like the one below:-
https://www.npmjs.com/package/html-to-image

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM