【问题标题】:PDF generated with mPDF not working on android使用 mPDF 生成的 PDF 无法在 android 上运行
【发布时间】:2017-03-25 13:49:00
【问题描述】:

我已经用 PHP 创建了网站。我使用了一个按钮生成 PDF,它在 ipad 和桌面上完美运行,但在 android 上无法运行。当我在 android 上生成 PDF 并尝试打开它时,pdf 阅读器会出错。我用两个不同的 pdf 阅读器试了一下。两者都给出错误都显示文件格式错误,文件无法打开。为了生成 pdf,我使用了 mPDF 库。

function generatePdf($userData){
$PNG_WEB_DIR = 'phplib/qrcode'.DIRECTORY_SEPARATOR;

$id = $userData['Id'];
$name = $userData['FirstName'].' '.$userData['LastName'];;
$source =$userData['Source'];
$destination =$userData['Destination'];
$date =$userData['Date'] ;
$FlightName = $userData['FlightName'];
$FlightNumber=$userData['FlightNumber'];
$html .='<div style="text-align: center;">
        <h3 class="form-title">&nbsp;<font size=4>'.$name.'</h3>
        </div>
        <div style="text-align: center;">
        <table class="table" style="text-align: left;">
                <tr>
                    <td class="style" >TicketId:</td>
                    <td class="style">'.$id.'</td>

                </tr>
                <tr>
                    <td class="style">Source:</td>
                    <td class="style">'.$source.'</td>

                </tr>
                <tr>
                    <td class="style">Destination:</td>
                    <td class="style">'.$destination.'</td>
                </tr>
                <tr>
                    <td class="style">Flight Name:</td>
                    <td class="style">'.$FlightName.'</td>
                </tr>
                 <tr>
                <td class="style">Flight Number:</td>
                <td class="style">'.$FlightNumber.'</td>
                </tr>
                 <tr>
                <td class="style">Date:</td>
                <td class="style">'.$date.'</td>
                </tr>
                <tr>
                <td class="style">
                <img src="'.$PNG_WEB_DIR.$id.'.png" /></td>
                </tr>
            </table>
        </div>';
$mpdf=new mPDF();
$mpdf->debug = true;
$mpdf->allow_output_buffering = true;

$mpdf->WriteHTML($html);
//$mpdf->SetDisplayMode('fullpage');

$mpdf->Output('download.pdf','D');

【问题讨论】:

  • 代码??? ???????

标签: php android mpdf


【解决方案1】:

好的,我知道了。希望它也可以帮助你。问题不在于 android 或桌面。我在桌面上使用 firefox,在 android 中使用 chrome,在 ios 中使用 safari。代码在 safari 和 firefix 中有效,但在 chrome 中无效。这个帖子帮助了我。mpdf not working in Google Chrome but working fine in firefox

ob_clean();
header('Content-type: application/pdf');
header('Content-Disposition: inline; filename="' . $yourFileName . '"');
header('Content-Transfer-Encoding: binary');
header('Accept-Ranges: bytes');

require_once 'mpdf60/mpdf.php';
$mpdf=new mPDF('c','A4','','' , 0 , 0 , 0 , 0 , 0 , 0); 

$mpdf->SetDisplayMode('fullpage');

$mpdf->list_indent_first_level = 0; 
$stylesheet = file_get_contents('css/style.css');
$mpdf->WriteHTML($stylesheet,1);
$mpdf->WriteHTML($test, 2);
$mpdf->Output();  
ob_end_flush();

我只是通过引用这个来更改我的代码并且它有效。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-05-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-08
    • 1970-01-01
    • 2015-08-07
    相关资源
    最近更新 更多