php 在 DOMPDF 中打印边距

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11649052/
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-25 01:47:27  来源:igfitidea点击:

Print margins in DOMPDF

phppdfdompdf

提问by cyrodiil

I'm trying to generate a PDF using DOMPDF. I have some HTML which is then converted into a PDF.

我正在尝试使用 DOMPDF 生成 PDF。我有一些 HTML,然后将其转换为 PDF。

But I have a problem. When I put an object at the top of the page (e.g. an icon), in the PDF it's also show on the top of the page. But when I print the PDF there is a margin. I know that there has to be a minimal margin, but in my case it's just too large. Is there some way to control this margin in DOMPDF?

但我有一个问题。当我将对象放在页面顶部(例如图标)时,在 PDF 中它也会显示在页面顶部。但是当我打印 PDF 时,有一个边距。我知道必须有一个最小的余量,但在我的情况下它太大了。有没有办法在 DOMPDF 中控制这个边距?

I'm trying to reproduce an existing document and in the original the logo is not on the top of the page (there is already a margin in the PDF). But when I print it, it's located at the exact same position as in the PDF generated by me (and there is no margin in the PDF).

我正在尝试复制现有文档,但在原始文档中,徽标不在页面顶部(PDF 中已经有边距)。但是当我打印它时,它的位置与我生成的 PDF 中的位置完全相同(并且 PDF 中没有边距)。

Is there somewhere a print margin already set in the PDF?

PDF 中是否已经设置了打印边距?

回答by BrianS

The following style will effectively set the margins of your document to 0:

以下样式将有效地将文档的边距设置为 0:

@page { margin: 0px; }
body { margin: 0px; }

@pageis used by dompdf 0.6.0, bodyby dompdf 0.5.1. You can modify the margin of the page and body independently, though right now the margin of the two together acts as your content bounds.

@page由 dompdf 0.6.0 使用,body由 dompdf 0.5.1 使用。您可以独立修改页面和正文的边距,但现在两者的边距一起充当您的内容边界。

回答by Pierlo Upitup

sometimes you also need to set

有时你还需要设置

html?{ margin: 0px}