Html 如何指定 PDF 大小?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3455016/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 04:04:56  来源:igfitidea点击:

How are PDF sizes specified?

htmlpdf

提问by Verhogen

I am generating a PDF from HTML using a library, and all the size parameters that I am giving are in pixels. This seems kind of odd. I just googled the internet for A4 size in pixels, and can I just use these values everywhere?

我正在使用库从 HTML 生成 PDF,并且我提供的所有大小参数都以像素为单位。这似乎有点奇怪。我刚刚在互联网上搜索了 A4 尺寸的像素,我可以在任何地方使用这些值吗?

Is this how it should be done? Will the generated PDF look correctly?

这是应该怎么做?生成的 PDF 会正确显示吗?

Otherwise, do I need to somehow compute the pixel size using information from the screen?

否则,我是否需要使用屏幕上的信息以某种方式计算像素大小?

Then, how do PDF's work if they can be sent to others and still look comparatively the same?

那么,如果可以将PDF发送给其他人并且看起来仍然比较相同,那么PDF如何工作?

回答by

PDF internally uses the same graphics model as PostScript. PDF is derived from PostScript. Basically,...

PDF 在内部使用与 PostScript 相同的图形模型。PDF 源自 PostScript。基本上,...

  • ...it uses the very same operators that are available in PostScript, but renames them from being long and fully readable to short 1-, 2- or 3-letter abbreviations;
  • ...however, it strips all features that make PostScript a full-blown programming language;
  • ...and it adds a few new graphics capabilities, such as tranparencies and direct TrueType fonts embedding.
  • ...它使用与 PostScript 中可用的完全相同的运算符,但将它们从长且完全可读的重命名为短的 1、2 或 3 个字母缩写;
  • ...然而,它剥夺了使 PostScript 成为成熟编程语言的所有功能;
  • ...它添加了一些新的图形功能,例如透明胶片和直接嵌入 TrueType 字体。

PDF also uses the same basic measurement unit as PostScript: 72 points == 1 inch. You may also use fractions of points. This is the device independentway of stating dimensions.

PDF 还使用与 PostScript 相同的基本度量单位:72 点 == 1 英寸。您也可以使用分数的分数。这是与设备无关的表示尺寸的方式。

If you ever use pixels, you can do so. If you do, the absolute size of a graphic object on the display or the printed paper then depends on the current resolution of the display or printer. A square of 72px x 72px is 1inch x 1inch at a 72dpi resolution, but it is 0.1inch x 0.1inch at a 720dpi resolution. Therefore using pixels is a device dependentway of stating dimensions.

如果您曾经使用过像素,则可以这样做。如果这样做,则显示器或打印纸上图形对象的绝对大小取决于显示器或打印机的当前分辨率。72px x 72px 的正方形在 72dpi 分辨率下为 1inch x 1inch,但在 720dpi 分辨率下为 0.1inch x 0.1inch。因此,使用像素是一种与设备相关的表示尺寸的方式。

A4 dimensions are 'width x height = 595 x 842 pt'.

A4 尺寸为'width x height = 595 x 842 pt'

回答by Marc B

PDF's inherently a print medium, and its internal coordinates work in terms of 'points' (72pts per inch). The PDF rendering software (Acrobat, FoxIt, Ghostscript, etc...) will query the output device for its DPI rating and internally convert all the point-basec coordinates into device-specific pixel sizes when it comes time to render the PDF for display/print.

PDF 本质上是一种打印介质,其内部坐标以“点”(每英寸 72 磅)为单位。PDF 渲染软件(Acrobat、FoxIt、Ghostscript 等)将查询输出设备的 DPI 等级,并在渲染 PDF 以供显示时在内部将所有基于点的坐标转换为设备特定的像素大小/打印。

You can specify sizes in pixels while building a PDF, certainly. But remember that pixel sizes differ. A 300x300 pixel image will be 1" x 1" square on a 300dpi printer, but 3" by 3" on a 100 dpi monitor.

当然,您可以在构建 PDF 时以像素为单位指定大小。但请记住,像素大小不同。300x300 像素的图像在 300dpi 打印机上为 1" x 1" 正方形,但在 100 dpi 显示器上为 3" x 3"。