我有以下代码可以开始。
<?
require('html2fpdf.php');
$pdf=new HTML2FPDF();
$pdf->AddPage();
$fp = fopen("en/print-job.php?ID=12","r");
$strContent = fread($fp, filesize("en/print-job.php?ID=12"));
fclose($fp);
$pdf->WriteHTML($strContent);
$pdf->Output("home.pdf");
echo "PDF file is generated successfully!";
?>
我有一个名为print-pdf.php的页面,该页面建立在引导程序上,并且输出是这样的:
https://www.lotomanager.in/en/print-job.php?ID=12
那么如何将该页面直接转换为pdf?
我从上面的代码中得到以下结果:
警告:fopen(zh-cn / print-job.php?ID = 12):无法打开流:在第5行的/home/loto/public_html/pdf.php中没有此类文件或目录
警告:filesize():第6行的/home/loto/public_html/pdf.php中en / print-job.php?ID = 12的统计信息失败
警告:fread()期望参数1为资源,在第6行的/home/loto/public_html/pdf.php中提供布尔值
警告:fclose()期望参数1为资源,在第7行的/home/loto/public_html/pdf.php中给定的布尔值已成功生成PDF文件!
试试这个
<?php
require_once 'dompdf/autoload.inc.php';
?>
<?php
// reference the Dompdf namespace
use Dompdf\Dompdf;
// instantiate and use the dompdf class
$html = file_get_contents('http://www.lotomanager.in/en/print-job.php?ID=12');
$dompdf = new Dompdf();
$dompdf->loadHtml($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();
?>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句