我正在使用dompdf(一个PHP库)来创建PDF页面,我在设置适当的尺寸时遇到了问题。当我使用CSS属性时:
@page {
size: 21cm 29.7cm;
}
...例如,我希望页面的上半部分为红色,PDF文件正常,但打印后我有白色边距。我该如何解决?
答案 0 :(得分:4)
您已设置了网页的大小,但未设置内容边界。如果您不想在页面上有任何边框,则必须将页边距设置为0。
@page {
size: 21cm 29.7cm;
margin: 0;
}
这会删除正文周围的边距,但这也意味着您的内容会突破页面边缘。如果你希望身体内容与边缘有一些间距,请给它一些填充。
body {
padding: .5in;
}
答案 1 :(得分:0)
nolbadi111:
您是否使用setPaper()函数设置了正确的纸张尺寸?
// reference the Dompdf namespace
use Dompdf\Dompdf;
// instantiate and use the dompdf class
$dompdf = new Dompdf();
$dompdf->loadHtml('hello world');
// (Optional) Setup the paper size and orientation
$dompdf->setPaper('A4', 'landscape');
// Render the HTML as PDF
$dompdf->render();
// Output the generated PDF to Browser
$dompdf->stream();
答案 2 :(得分:0)
好的,问题不在于domPDF,而在于打印机设置。要实现目标,您必须设置无边界属性。
顺便说一句。当你使用
$dompdf->setPaper('A4', 'landscape');
您不需要在css中设置页面大小属性(但在html中创建页面时有帮助)