dompdf:A4页面的白边 [英] dompdf: white margin on A4 page

查看:391
本文介绍了dompdf:A4页面的白边的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用dompdf(一个PHP库)来创建一个PDF页面,并且我有一个问题来设置正确的尺寸。当我使用CSS属性时:

I am using dompdf (a PHP library) to create a PDF page and I have a problem to set proper dimensions. When I use CSS property:

@page {
    size: 21cm 29.7cm; 
}

...例如我想让页面的上半部分为红色颜色,PDF文件是好的,但打印后我得到了白色的边缘。我怎样才能解决它?

… and for example I want to have the upper part of the page in red color, the PDF file is OK, but after print I got white margin. How can I fix it?

推荐答案

您已设置页面的大小,但不是内容边界。如果您不希望页面上有任何边框,则必须将页边距设置为0。

You've set the size of the page, but not the content boundaries. If you don't want any border on the page you have to set the page margins to 0.

@page {
  size: 21cm 29.7cm;
  margin: 0;
}

这消除了身体边缘,但这也意味着您的内容将碰到页面边缘。如果你希望body内容与边缘有一定的间距,可以给它一些填充。

This removes the margin around the body, but it also means that your content will bump up against the page edge. If you want the body content to having some spacing from the edge give it some padding.

body {
  padding: .5in;
}

这篇关于dompdf:A4页面的白边的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆