1

I am creating a canvas with predefined dimensions (2505px width, 3542px height) which are the dimensions for an A4 paper in 300 DPI resolution.

I am converting the canvas to pdf using createPDFStream (https://github.com/Automattic/node-canvas#canvascreatepdfstream). The outputted PDF is good but I notice that the Page Size is 34,79 x 49,19 inches (see image below), which is much larger than a regular A4 paper, which causes some problems further down the line.

I notice that this is because that createPDFStream is assuming that the PDF should be in 72dpi, since 2505px / 72dpi = 34,79 inches & 3542px / 72 dpi = 49,19 inches. My question is if there is a way to specify to createPDFStream that the PDF is supposed to be in 300dpi so that we get the correct Page Size. Alternatively, if there is a library to use to correct the Page Size or DPI settings without compromising the 300 DPI image quality.

I tried digging deeply through the node-canvas for a solution, but I could neither find a way to correct the DPI nor find the place where the 72 DPI assumption is set.

enter image description here

Alien13
  • 558
  • 3
  • 8
  • 30
  • Yes, that is because pdf for canvas is assuming we want 72 dpi. My worry is that if I use this, the output in that case will no longer be in 300 dpi resolution. But I will try that, maybe I can initiate the canvas using those exact values, and later scale it up for 300 dpi, in that case maybe I will get the correct size in inches without compromising my 300 dpi resolution, I didn't consider this, I will try, thanks! – Alien13 Mar 10 '22 at 09:12
  • Are you implying that if I create the canvas with those dimensions (595.276, 841.890) and I just add my 300 DPI images like I would normally do (usually the images are thousands of pixels wide and high). Then I will get the PDF in the right page size and still have my image in 300 DPI?) – Alien13 Mar 10 '22 at 21:17
  • https://github.com/shutterstock/changeDPI is a useful library for changing the dpi of a base64 image before you embed it into a pdf. – melchiar Mar 11 '22 at 05:41

0 Answers0