从链接PHP生成PDF

时间:2018-12-21 12:30:32

标签: php pdf mpdf html-to-pdf

include('MPDF57/mpdf.php');


$html.= "Here I shoud have to call a php Generated html file named 'report_pdf.php'";
$mpdf=new mPDF('c', 'A4-L');
$mpdf->WriteHTML($html);
$mpdf->SetDisplayMode('fullpage');
// $mpdf->SetOrientation('L');

$mpdf->Output();

在上述HTML变量中的代码中,我想调用生成HTML代码的PHP文件 注意:不能使用file_get_contents()

3 个答案:

答案 0 :(得分:0)

如果您不能使用file_get_contents,则可以为此使用CURL,例如:

$ch = curl_init("https://example.com/report_pdf.php");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
$content = curl_exec($ch);
curl_close($ch);

如果调用成功,$content变量中将包含HTML代码。

答案 1 :(得分:0)

您可以使用输出缓冲ob_start() / ob_end_clean()

替换:

$html.= "Here I shoud have to call a php Generated html file named 'report_pdf.php'";

使用:

ob_start();
include('report_pdf.php');
$html .= ob_end_clean();

尽管它取决于report_pdf.php文件的结构(它需要或做什么)以及“生成的名为'report_pdf.php'的html文件”

的含义。 >

答案 2 :(得分:0)

请尝试以下代码,它对我有用。 但是我使用了 TCPDF

$pdf=new mPDF('c', 'A4-L');
$pdf->AddPage();

        // FETCH HTML
        ob_start();
        include_once(CONTENT_PATH."filename.php");
        $rpcontent=ob_get_contents();
        ob_end_clean();
        // FETCH HTML

$htmlcontent = $rpcontent;

// output the HTML content
$pdf->writeHTML($htmlcontent, true, 0, true, 0);
$pdf->lastPage();

$pdf->Output($pdf_file, "I"); // I for sending the file inline to the browser
$pdf->Output(REPORT_PATH.test.pdf, "F"); //F for saving output to file 
相关问题