我在codeigniter中使用TCPDF创建PDF文件。我已成功创建PDF并将其保存到给定的文件夹。但是,成功完成后无法在浏览器中显示它。
我在stackoverflow中阅读了很多查询。我已经尝试在Chrome和Mozilla Firefox浏览器中使用。
$pdffilename = rand() . '-content.pdf';
//Full path to save PDF File
$pdffullpath = $_SERVER['DOCUMENT_ROOT'] . 'myweb/export-files/pdf/' . $pdffilename;
//Full path to display PDF file in browser
$localpdffile = base_url('export-files/pdf/' . $pdffilename);
//TCPDF saving PDF to given folder and file name
$pdf->Output($pdffullpath, 'F');
现在我明白了。
$pdffilename = rand() . '-content.pdf';
//Full path to save PDF File
$pdffullpath = $_SERVER['DOCUMENT_ROOT'] . 'myweb/export-files/pdf/' . $pdffilename;
//Full path to display PDF file in browser
$localpdffile = base_url('export-files/pdf/' . $pdffilename);
//TCPDF saving PDF to given folder and file name
$pdf->Output($pdffullpath, 'F');
echo "<div class='text-center'><embed src='$localpdffile' type='application/pdf' width='90%' height='700px' /></div>";
我可以在Chrome和Firefox中成功显示PDF。 我可以在写这个问题的同时解决我的问题。谢谢。