5

我安装了 MPDF 实用程序以便将 HTML&CSS 转换为 PDF 报告。到目前为止一切正常,直到我尝试将某些页面转换为 PDF 并且没有输出。

我不得不提一下,我可以通过浏览器定期显示该页面 - 只有在我尝试将其转换为 PDF 时才会出现问题 - 然后我收到空白页。此外,没有编码问题(部分输出是用希伯来语编写的,但我已经克服了这个障碍)

这是代码的一部分:

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;

有什么建议么?

提前致谢

4

3 回答 3

6

你试过调试它吗?根据 mpdf 的网站:如果您在浏览器上只看到一个空白屏幕,则可能是因为存在脚本错误。在脚本开始时打开调试。

<?php
include("../mpdf.php");
$mpdf=new mPDF();

$mpdf->debug = true;

$mpdf->WriteHTML("Hallo World");
$mpdf->Output();
?>

如果上述方法有效,那么它与您的代码有关。有时,即使在任何 html 输出之前的一个空格也可以摆脱 MPDF

于 2011-11-14T14:57:55.197 回答
3

首先,如果您在浏览器上只看到一个空白屏幕,那可能是因为存在脚本错误。在脚本开始时打开调试。

// 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();

并在 mPDF 代码之前添加这个 php 内置函数(在你调用 mpdf 之前)

ob_end_flush();

require_once __DIR__ . '/vendor/autoload.php';

$mpdf = new \Mpdf\Mpdf();
$mpdf->WriteHTML($html);
$mpdf->Output();

这样它将在处理 mPDF 之前清除所有缓冲区输出。

确保您是否使用任何功能,然后将其保留在同一页面中。

于 2020-09-10T15:43:56.990 回答
-2
<?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();


?>

你可以尝试链接this.but你会得到第二页空白,但在第一页你会得到详细信息。

谢谢桑克特。

于 2014-01-24T09:02:47.580 回答