PHP

PHP DOMPDF如何设置页面大小

小樊
106
2024-08-19 09:27:37
栏目: 编程语言

PHP DOMPDF可以通过设置页面大小参数来指定生成PDF文件的页面尺寸。可以通过以下方式设置页面大小:

// Include the DOMPDF library
require 'dompdf/autoload.inc.php';

// Create an instance of the DOMPDF class
$dompdf = new Dompdf\Dompdf();

// Set the paper size and orientation
$dompdf->set_paper('A4', 'portrait');

// Load HTML content
$html = file_get_contents('example.html');

// Convert HTML to PDF
$dompdf->load_html($html);
$dompdf->render();

// Output the generated PDF
$dompdf->stream('output.pdf');

在上述示例中,通过set_paper()方法设置页面尺寸为A4并指定为纵向方向。可以根据需要将页面尺寸设置为其他尺寸,如Letter、Legal等,以及指定页面的方向为横向或纵向。

0
看了该问题的人还看了