php 如何使用dompdf设置pdf的自定义宽度和高度?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25376901/
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
How to set custom width and height of pdf using dompdf?
提问by Saurabh Gupta
When I create my pdf using dompdf it generates it as default width and height. I want to set custom width and height of my created pdf. If it is not possible in dompdf then kindly suggest some other plugin for php.
当我使用 dompdf 创建我的 pdf 时,它会将其生成为默认宽度和高度。我想设置我创建的 pdf 的自定义宽度和高度。如果在 dompdf 中不可能,那么请建议一些其他的 php 插件。
回答by Jorge Caballero
By default it's going to render on 'US Letter', you can change this by using:
默认情况下,它将呈现在“美国信函”上,您可以使用以下方法进行更改:
$dompdf->set_paper(DEFAULT_PDF_PAPER_SIZE, 'portrait');
You can use 'letter', 'legal', 'A4', etc..
您可以使用“信件”、“法律”、“A4”等。
Nevertheless you can set your own size like this:
不过,您可以像这样设置自己的尺寸:
$customPaper = array(0,0,360,360);
$dompdf->set_paper($customPaper);
More info: https://github.com/dompdf/dompdf/wiki/Usage