【问题标题】:Get Printers dialog when using mPDF instead of Save As dialog使用 mPDF 而不是另存为对话框时获取打印机对话框
【发布时间】:2014-04-17 15:04:53
【问题描述】:

当用户在我的 PHP 页面而不是 SaveAs 窗口中按下“打印”时,我正在尝试找到一种方法来打开“选择打印机”对话框。

我在这里阅读了所有帖子,找不到有效的回复。 还阅读了这篇文章: mPDF auto print issue

但以下代码会打开另存为窗口,而不是“选择打印机”窗口:

$pdf=new mPDF('en','A4','','DejaVuSansCondensed',$template->margin_left,$template->margin_right,$template->margin_top,$template->margin_bottom,$template->margin_header,$template->margin_footer);

$pdf->setAutoFont();

$pdf->SetHTMLHeader($header);

$pdf->SetHTMLFooter($footer);

$pdf->SetJS('this.print();');

$pdf->writeHTML($printable);

$pdf->输出();

谁能帮忙? 为什么我仍然得到“另存为”窗口?

【问题讨论】:

    标签: php printing mpdf


    【解决方案1】:

    要获得打印对话框,你可以简单地使用 JS

    window.onload = function() { window.print(); }
    

    MPDF 功能:- 你也可以使用

    <?php
    // Saves file on the server as 'filename.pdf'
    $mpdf=new mPDF();
    $mpdf->WriteHTML('<p>Hallo World</p>');
    $mpdf->Output('filename.pdf','F');
    ?>
    

    添加“D”参数下载

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

    也请参考How to open print dialog after pdf generated?

    【讨论】:

    • 谢谢,但这对我没有帮助。 window.print();打印我所在的页面,它不是 PDF,它是另一个 php 页面。我需要打开打印机对话框来打印 PDF,而不是窗口。也使用参数“D”或“F”调用输出是不相关的,因为我想打印 pdf,而不是将其保存为文件。如您在上面看到的,我正在尝试从 PHP 代码打印 PDF
    猜你喜欢
    • 1970-01-01
    • 2011-06-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多