Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/233.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何将HTML页面布局保存为PDF_Php_Html_Css_Pdf - Fatal编程技术网

Php 如何将HTML页面布局保存为PDF

Php 如何将HTML页面布局保存为PDF,php,html,css,pdf,Php,Html,Css,Pdf,我使用的是程序风格的5.1.6版核心PHP 如何将HTML页面保存为包含精确布局信息的PDF 我目前的专业是,每当我试图通过单击“另存为pdf”链接/按钮将a_pahe.html保存为pdf时,它会保存html页面,但会丢失我需要的所有布局 我的HTML页面的确切布局是 生成的PDF输出如下所示 尝试使用 您还可以使用外部css在上进行此操作 <link rel="stylesheet" type="text/css" href="print.css" media="print">

我使用的是程序风格的5.1.6版核心PHP

如何将HTML页面保存为包含精确布局信息的PDF

我目前的专业是,每当我试图通过单击“另存为pdf”链接/按钮将a_pahe.html保存为pdf时,它会保存html页面,但会丢失我需要的所有布局

我的HTML页面的确切布局是

生成的PDF输出如下所示 尝试使用

您还可以使用外部css在上进行此操作

<link rel="stylesheet" type="text/css" href="print.css" media="print">

正确配置的wkhtmltopdf可能是服务器端pdf呈现所需的内容。

使用dompdf库:

Dompdf是一个HTML到PDF的转换器。 只需下载并安装它(阅读文档), 然后将HTML传递到dompdf并流式输出:

// reference the Dompdf namespace
use Dompdf\Dompdf;

// instantiate and use the dompdf class
$dompdf = new Dompdf();
$dompdf->loadHtml(file_get_contents('exemple.html'));

// (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();

使用php5.1?哇!但我不想打印数据,我想保存在PDF@NaveenK.Sanadhya浏览器在打印时具有“另存为PDF”功能
// reference the Dompdf namespace
use Dompdf\Dompdf;

// instantiate and use the dompdf class
$dompdf = new Dompdf();
$dompdf->loadHtml(file_get_contents('exemple.html'));

// (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();