【问题标题】:How to send the PDF output to browser print option (CTRL+P)如何将 PDF 输出发送到浏览器打印选项 (CTRL+P)
【发布时间】:2014-10-13 08:31:02
【问题描述】:

我正在使用 TCPDF 库生成一些报告,并且我想将 PDF 文件发送到浏览器的打印选项,就像我们按 CTRL+P 一样简单,我需要这个,因为它是滑动的。 我使用了输出的所有参数,但它是直接下载文件。

$pdf->Output('slip.pdf', 'I');

我也将 F、D、S、E、FI 和 FD 置于 I 状态,但它不起作用。而且我还使用了标题

header('Content-Type: application/pdf');
$pdf->Output('example_001.pdf', 'FD');

但它再次不起作用。有什么解决办法吗?请!

【问题讨论】:

    标签: printing tcpdf


    【解决方案1】:

    添加 $pdf->IncludeJS("print();"); 就在$pdf->输出...

    之前

    【讨论】:

    • 简单、智能的解决方案。节省了我的时间:)
    • 你的意思是$pdf->Output('slip.pdf', 'I');或 $pdf->Output('slip.pdf', 'F');
    • @Jarla 在 $pdf->Output 之前
    【解决方案2】:

    您需要类似以下示例的内容。您需要拦截打印请求(在页面加载、打印按钮点击等时自动打印),然后调用 printTrigger 函数。

    <html>
    <head>
        <title>Print PDF</title>
        <script>
            function printTrigger(elementId) {
                var getMyFrame = document.getElementById(elementId);
                getMyFrame.focus();
                getMyFrame.contentWindow.print();
            }
        </script>
    </head>
    
    <body>
        <iframe id="iFramePdf" src="http://pdfurl.com/sample.pdf"></iframe>
    ...
    </body>
    </html>
    

    【讨论】:

      【解决方案3】:

      您尝试执行的操作不在 TCPDF API 的规范范围内。

      http://www.tcpdf.org/doc/code/classTCPDF.html#a3d6dcb62298ec9d42e9125ee2f5b23a1

      我相信您需要使用 JavaScript 来按照您提议的方式实现此功能。

      【讨论】:

      • 但我不知道 javascript
      【解决方案4】:

      添加 $pdf->IncludeJS("print();");就在 $pdf-> 输出之前... 它对我有用。

      【讨论】:

      • 你的意思是$pdf->Output('slip.pdf', 'I');或 $pdf->Output('slip.pdf', 'F');
      猜你喜欢
      • 1970-01-01
      • 2010-10-18
      • 2010-09-17
      • 1970-01-01
      • 2010-09-16
      • 2018-09-16
      • 2015-03-04
      • 1970-01-01
      • 2019-01-16
      相关资源
      最近更新 更多