从画布转换为默认分辨率为 72 dpi 的 PDF 会导致页面大小不正确

发布于 2025-01-13 00:55:20 字数 918 浏览 5 评论 0原文

我正在创建一个具有预定义尺寸(2505 像素宽度,3542 像素高度)的画布,这是 300 DPI 分辨率的 A4 纸的尺寸。

我正在使用 createPDFStream 将画布转换为 pdf (https://github .com/Automattic/node-canvas#canvascreatepdfstream)。输出的 PDF 很好,但我注意到页面大小为 34,79 x 49,19 英寸(见下图),比普通 A4 纸大得多,这会导致一些问题线。

我注意到这是因为 createPDFStream 假设 PDF 的分辨率应为 72dpi,因为 2505px / 72dpi = 34,79 英寸 & 3542px / 72 dpi = 49.19 英寸。我的问题是,是否有一种方法可以指定 createPDFStream PDF 的分辨率应为 300dpi,以便我们获得正确的页面大小。或者,如果有一个库可用于在不影响 300 DPI 图像质量的情况下更正页面大小DPI 设置

我尝试深入挖掘 node-canvas 来寻找解决方案,但我既找不到纠正 DPI 的方法,也找不到设置 72 DPI 假设的位置。

输入图片此处描述

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文