1

I'm looking to use PDFJS to embed PDFs into a webpage. I'd like to render them into a fixed-width canvas (and have them scaled appropriately so they fit into the canvas), while having similar resolution/image quality as the original PDF. If I use a viewport generated like this:

var viewport = 
page.getViewport(page.getViewport(canvas.width/page.getViewport(1.0).width);

I get very low-quality image rendering for small-ish canvases. Is there a way to specify both the scale at which a PDF should be rendered and a suggestion for resolution/image quality?

I'm assuming some method of using/resizing a wrapper div may be the solution, but my attempts thus far have not been successful in scaling the contents of the canvas.

(Also, I know this is related to this other post, but that post doesn't mention a way to specify a higher quality pdf rendering for small canvases).

J. Jane
  • 13
  • 2
  • PDFJS renders at highest possible quality on the canvas. Do you mean to use HiDPI display? If yes, use displayPixelRatio to increase amount of pixels on the canvas, but keep CSS size you want. – async5 May 04 '17 at 17:47
  • Cool, thanks. How do I use displaypixelratio? Namely where do I set it/pass it? – J. Jane May 05 '17 at 19:35
  • if using PDF.js core library is too hard, you can start using its ui components, see https://github.com/mozilla/pdf.js/blob/master/examples/components/simpleviewer.js and/or see PDFPageView is implemented. – async5 May 05 '17 at 20:13

0 Answers0