Php MPDF无输出(空白页)
我安装了MPDF实用程序,以便将HTML和CSS转换为PDF报告。 到目前为止,一切都很顺利,直到我尝试将某个页面转换为PDF,但没有输出 我必须提到的是,我能够通过浏览器定期显示页面——只有当我试图将其转换为PDF时才会出现问题——然后我会收到空白页面。此外,没有编码问题(部分输出是用希伯来语编写的,但我已经克服了这个障碍) 以下是部分代码:Php MPDF无输出(空白页),php,mpdf,Php,Mpdf,我安装了MPDF实用程序,以便将HTML和CSS转换为PDF报告。 到目前为止,一切都很顺利,直到我尝试将某个页面转换为PDF,但没有输出 我必须提到的是,我能够通过浏览器定期显示页面——只有当我试图将其转换为PDF时才会出现问题——然后我会收到空白页面。此外,没有编码问题(部分输出是用希伯来语编写的,但我已经克服了这个障碍) 以下是部分代码: if($customer!=$tempCustomer) { if($tempCustomer!="") { $html.=
if($customer!=$tempCustomer)
{
if($tempCustomer!="")
{
$html.=("</table>");
$html.=("</BR>סהכ".$sumTotal."</BR>");
$html.=("</BR>משטחים".$sumPallets."</BR>");
}
$sumTotal=0; //RESET SUM OF EACH CUSTOMER
$sumPallets=0; //RESET PALLETS COUNT
$html.=("</div>");
$html.=("<div class='subTable'>");
// $html.=("לקוח: ".$customerName."</br>");
$sumTotal=0;
$sumPallets=0;
$tempCustomer=$customer;
$html.=("<table border='3'
<tr><td>מגדל</td><td>תאריך</td><td>תעודה</td><td>פריט</td><td>סוג</td><td>גודל</td><td>כמות</td><td>משקל</td><td>מחיר
מכירה</td><td>סכום</td><td>משטחים</td></tr>");
$html.=("<tr>");
$html.=("<td>".$grower."</td>");
$html.=("<td>".$date."</td>");
$html.=("<td>".$form."</td>");
$html.=("<td>".$item."</td>");
$html.=("<td>".$type."</td>");
$html.=("<td>".$size."</td>");
$html.=("<td>".$quantity."</td>");
$html.=("<td>".$weight."</td>");
$html.=("<td>".$price."</td>");
$html.=("<td>".$total."</td>");
$html.=("<td>".$pallet."</td>");
$html.=("</tr>");
$sumTotal+=$total;
$sumPallets+=$pallet;
}
else
{
$html.=("<tr>");
$html.=("<td>".$grower."</td>");
$html.=("<td>".$date."</td>");
$html.=("<td>".$form."</td>");
$html.=("<td>".$item."</td>");
$html.=("<td>".$type."</td>");
$html.=("<td>".$size."</td>");
$html.=("<td>".$quantity."</td>");
$html.=("<td>".$weight."</td>");
$html.=("<td>".$price."</td>");
$html.=("<td>".$total."</td>");
$html.=("<td>".$pallet."</td>");
$html.=("</tr>");
$sumTotal+=$total;
$sumPallets+=$pallet;
}
/*
$html.=("<td>".$form."</td>");
$html.=("<td>".$form."</td>");
$html.=("<td>".$form."</td>");
$html.=("<td>".$form."</td>");
$html.=("<td>".$form."</td>");
$html.=("<td>".$form."</td>");
$html.=("<td>".$form."</td>");
$html.=("<td>".$form."</td>");
$html.=("<td>".$form."</td>");
$html.=("<td>".$form."</td>");
$html.=("</tr>");
*/
}
$html2='אבדרכדכגכגכגכג';
$html3='אבדרכדכגכגכגכג';
//==============================================================
//MPDF SETTINGS - CONTINUE
$mpdf->SetAutoFont();
$mpdf->autoFontGroupSize = 1;
$mpdf->SetDirectionality('rtl');
$mpdf->useLang = true;
$mpdf->WriteHTML($html);
$mpdf->Output();
exit;
if($customer!=$tempCustomer)
{
如果($tempCustomer!=“”)
{
$html.=(“”);
$html.=(“הכ”$sumTotal。””;
$html.=(“שטים”。$sumPallets。””;
}
$SUMTOAL=0;//重置每个客户的总和
$sumPallets=0;//重置托盘计数
$html.=(“”);
$html.=(“”);
//$html.=($customerName.);
$sumTotal=0;
$sumPallets=0;
$tempCustomer=$customer;
$html.=(“您试过调试它吗?根据mpdf的网站:如果您的浏览器上只有一个空白屏幕,可能是因为存在脚本错误。请在脚本开始时启用调试
<?php
include("../mpdf.php");
$mpdf=new mPDF();
$mpdf->debug = true;
$mpdf->WriteHTML("Hallo World");
$mpdf->Output();
?>
// Require composer autoload
require_once __DIR__ . '/vendor/autoload.php';
try {
$mpdf = new \Mpdf\Mpdf();
$mpdf->debug = true;
$mpdf->WriteHTML("Hello World");
$mpdf->Output();
} catch (\Mpdf\MpdfException $e) { // Note: safer fully qualified exception
// name used for catch
// Process the exception, log, print etc.
echo $e->getMessage();
}
如果上述方法有效,那么这就是你的代码。有时,在任何html输出之前的一个空格都会导致MPDF失效
<?php
include_once("mpdf-master/mpdf.php");
include_once('../../../../wp-load.php');
$htm = get_template_directory_uri().'/admin/_invoice.php?id='.$_GET['id'];
$html = file_get_contents("$htm");
$mpdf=new mPDF('c');
$mpdf->WriteHTML($html);
$mpdf->Output();
?>
你可以尝试链接这个。但是你会得到第二页空白,但在第一页你会得到详细信息
谢谢
Sanket.首先,如果浏览器上只有一个空白屏幕,可能是因为出现了脚本错误。请在脚本开始时启用调试
<?php
include("../mpdf.php");
$mpdf=new mPDF();
$mpdf->debug = true;
$mpdf->WriteHTML("Hallo World");
$mpdf->Output();
?>
// Require composer autoload
require_once __DIR__ . '/vendor/autoload.php';
try {
$mpdf = new \Mpdf\Mpdf();
$mpdf->debug = true;
$mpdf->WriteHTML("Hello World");
$mpdf->Output();
} catch (\Mpdf\MpdfException $e) { // Note: safer fully qualified exception
// name used for catch
// Process the exception, log, print etc.
echo $e->getMessage();
}
之后,如果有任何错误,如
Data has already been sent to output, unable to output PDF file
这意味着在使用mPDF创建pdf之前,一些数据存储在发送到浏览器的缓冲区中。因此无法创建pdf
就这么做。。
在为pdf准备数据时,在页面的第一行添加php内置函数
op_start();
并将此php内置函数添加到mPDF代码之前(在调用mPDF之前)
以便在处理mPDF之前清除所有缓冲区输出
如果您使用了任何函数,请确保将其保持在同一页中