TCPDF 销毁 HTML(空白页) [英] TCPDF destroyed HTML (blank page)

查看:48
本文介绍了TCPDF 销毁 HTML(空白页)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 TCPDF 的 PHP 项目.我有一个 PHP 文件,它使用引导程序创建了一个 HTML 主题.在这个文件中,我包含了我的 pdfGeneration.php.看起来像这样:

I have a PHP project in which I use TCPDF. I had a PHP File which creates an HTML theme with bootstrap. Inside this file I include my pdfGeneration.php. It looks like that:

require_once('tcpdf/tcpdf.php');
$pdfAuthor = "Test";
$pdfName = "Test.pdf";
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor($pdfAuthor);
$pdf->SetTitle($pdfName);
$pdf->SetSubject($pdfName);
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
$pdf->SetFont('dejavusans', '', 10);
$pdf->AddPage();

$htmlContent = 'Test';
$pdf->writeHTML($htmlContent, true, false, true, false, '');
ob_end_clean();

$outputFile = 'myServerPathHere';
$pdf->Output($outputFile, 'F');

echo '<span>PDF Creation finished. <a href="' . $outputFilePath . pdfName'" target='blank'>You can download the file here</a></span>';

如果我不包括这个 pdfGeneration 一切正常.但是当我包含它时,我只得到了一个空白的白色站点,结果是它的跨度.位于包含 pdfGeneration 的文件内的其余 HTML 代码完全丢失.我找不到错误?!

If I don't include this pdfGeneration everything works fine. But when I include it I got only a blank white site with that span in it as a result. The rest of the HTML code that is located inside the file that includes the pdfGeneration is totally lost. I can't find an error?!

我的目标是创建一个生成 pdf 的站点,在最好的情况下,直接在新选项卡中打开 pdf.我没有找到解决方案,所以我用链接解决了它.但我的第一个问题是缺少 HTML.

My goal is a site where the pdf is generated and in the best case, the pdf is directly opened in a new tab. I don't find a solution for that so I solved it with the link. But my first problem is the missing HTML.

推荐答案

请原谅我的问题,我自己发现了错误.函数ob_end_clean();"是错误.PHP 文档:ob_end_clean - 清理(擦除)输出缓冲区并关闭输出缓冲.这可能会导致之前生成的整个 HTML 代码丢失.如果我删除该命令,它会起作用.

Excuse my question, I found the error myself. The function "ob_end_clean(); " is the error. PHP Docs: ob_end_clean - Clean (erase) the output buffer and turn off output buffering. This probably causes the entire previously generated HTML code to be lost. If I remove the command it works.

这篇关于TCPDF 销毁 HTML(空白页)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆