【问题标题】:How to send pdf file to print dialog using php?如何使用 php 将 pdf 文件发送到打印对话框?
【发布时间】:2016-10-01 08:14:01
【问题描述】:

我在服务器上托管了 pdf 文件,并且希望当用户单击链接以打印 pdf 文件时,应该打开打印对话框,用户可以从那里打印该 PDF 文件。它应该可以在 Chrome、Firefox 和 Safari 浏览器中运行。

请让我知道如何在 PHP/jQuery 或 html/jQuery 中做到这一点?

【问题讨论】:

    标签: javascript php jquery html printing


    【解决方案1】:

    尝试以下代码一次

    $filepath = "path/to/file.pdf";
    $filename = "file.pdf";
    header('Content-Transfer-Encoding: binary');
    header('Content-Length: ' . filesize($filepath));  // File size
    header('Content-Encoding: none');
    header('Content-Type: application/pdf');
    header('Content-Disposition: attachment; filename=' . $filename);  // Make the browser display the Save As dialog
    readfile($filepath);  // This is necessary in order to get it to actually download the file, otherwise it will be 0Kb
    

    注意:这只是对 HTTP 协议的扩展;无论如何,一些浏览器可能会忽略它。

    【讨论】:

    • 这会将pdf文件下载到用户PC上。我需要在单击打印链接时打开打印对话框。这样用户就可以打印 PDF 文件了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-07-01
    • 2023-04-10
    • 2017-05-10
    • 2023-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多