开发者

MPDF No Output (Blank Page)

开发者 https://www.devze.com 2023-04-12 15:55 出处:网络
I\'d installed the MPDF utility in order to convert HTML&CSS to PDF reports. So far things have been working just fine开发者_如何学Python, until I\'ve tried converting certain page to PDF ,and the

I'd installed the MPDF utility in order to convert HTML&CSS to PDF reports. So far things have been working just fine开发者_如何学Python, until I've tried converting certain page to PDF ,and there's no output.

I have to mention that i'm able to display the page regularly through browser - the problem only comes up when i'm trying to convert it to PDF - then I receive blank page. Moreover, there are no encoding problems (part of the output is written in Hebrew, but I've already overcame this obstacle)

Here's part of the code :

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;

Any suggestions?

Thanks in advance


Have you tried debugging it? Per mpdf's site: If you get nothing but a blank screen on your browser, it may be because there is a script error. Turn on debugging at the start of your script.

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

$mpdf->debug = true;

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

If the above works, then it's something with your code. Sometime, even a single space before any html output can throw off MPDF


First of all, If you get nothing but a blank screen on your browser, it may be because there is a script error. Turn on debugging at the start of your script.

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

After that if there is any error like

Data has already been sent to output, unable to output PDF file

This means before creating pdf with mPDF some data is stored in the buffer which is sended to the browser. Therefore it is unable to create PDF.

Just do this.. Add this below php built-in function at the first line of your page were you are preparing data for pdf.

op_start();

And add this php built-in function before mPDF code (before where you are calling mpdf)

ob_end_flush();

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

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

So that it will clear all buffer output before processing mPDF.

Make sure if you use any functions then keep it in the same page.


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


?>

You can try link this.but you will get seconde page blank but in first page you will get the detail.

Thanks Sanket.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号