php 如何使用html2pdf打印html页面
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6183323/
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 use html2pdf to print html pages
提问by Mohan Ram
I am using html2pdf
library in order to generate pdf from html file.
我正在使用html2pdf
库来从 html 文件生成 pdf。
I don't know how to check out width arrangements.
我不知道如何检查宽度安排。
I had this library from source forge. If anyone has idea about it or manual about html2pdf
?
我从 source forge 获得了这个库。如果有人对此有想法或手册html2pdf
?
回答by IAmTimCorey
I think what you are asking is how to change the page width of the outputted PDF file. The answer is to change the width in the settings before you call AddPage(). Hereis an example of how to do so: Hereare the settings you will need: Basically, it would look something like this:
我认为您要问的是如何更改输出的 PDF 文件的页面宽度。答案是在调用 AddPage() 之前更改设置中的宽度。 以下是如何执行此操作的示例: 以下是您需要的设置: 基本上,它看起来像这样:
require("html2fpdf.php");
$htmlFile = "http://www.cnn.com";
$buffer = file_get_contents($htmlFile);
$pdf = new HTML2FPDF('P', 'mm', 'Legal');
$pdf->AddPage();
$pdf->WriteHTML($buffer);
$pdf->Output('my.pdf', 'F');
This, if I am getting the code right, would output a PDF called my.pdf that is formatted as a legal-size page in portrait mode.
如果我得到正确的代码,这将输出一个名为 my.pdf 的 PDF,该 PDF 格式为纵向模式下的合法尺寸页面。