简体   繁体   中英

Convert PDF to PNG inside browser

I'm using Vue.js and trying to convert PDF to PNG (or another image format) inside browser. Right now I'm able to read PDF from URL with PDF.js and Vue.js component pdfvuer like this:

var self = this;
self.pdfdata = pdfvuer.createLoadingTask(
  "https://any-pdf-link"
);
self.pdfdata.then(pdf => {
  console.log(pdf.numPages)
})

What should I do next to convert it to image?

Pdfvuer author here.

Pdfvuer/PDF.js renders PDFs as canvas elements. You can use the following code to generate a thumbnail from the first page.

let s = document.querySelectorAll('canvas')[0]
let imageDataUrl = s.toDataURL('img/png')

This will give you a base64 representation of the page.

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