简体   繁体   English

print.js 密码保护 pdf

[英]print.js password protected pdf

I try to create a frontend which shows all PDF files from a folder as dropdown.我尝试创建一个前端,将文件夹中的所有 PDF 文件显示为下拉列表。 The selected PDF should be silent printed over chrome kiosk printing mode.选定的 PDF 应通过 chrome kiosk 打印模式进行静音打印。 I'm a beginner with php and javascript, but on this steps there is no problem.我是 php 和 javascript 的初学者,但在这一步上没有问题。

The problem is, that the PDF's should be protected with a password and this makes the silent kiosk printing unpossible for me.问题是,PDF 应该用密码保护,这使得我无法在无声亭打印。

I need to send the password with print.js, but I don't think that there is a function in print.js.我需要用print.js发送密码,但我认为print.js中没有函数。

Another solution is to decrypt the PDF's with php, save it as temp file with suffix, print the pdf without password and delete the temp file.另一种解决方案是用 php 解密 PDF,将其保存为带后缀的临时文件,打印没有密码的 pdf 并删除临时文件。

Does anyone knows how I can do this?有谁知道我怎么能做到这一点? I searched for a solution to decrypt a PDF or a possibilty to send the password with print.js but doesn't found something.我搜索了解密 PDF 的解决方案或使用 print.js 发送密码的可能性,但没有找到任何东西。

Thank you very much for your help!非常感谢您的帮助!

<?php
$dir = "Path-to-PDF/";
$files = glob("$dir*.pdf",GLOB_BRACE);

?>
<!DOCTYPE html>
<html lang="de">
    <head>
        <title>Browser Title</title>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" href="inc/css/bootstrap.min.css">
        <link rel="stylesheet" href="inc/css/bootstrap-select.min.css">
        <script src="inc/js/jquery-3.5.1.min.js"></script>
        <script src="inc/js/bootstrap.bundle.min.js"></script>
        <script src="inc/js/bootstrap-select.min.js"></script>
        <script src="inc/js/print.min.js"></script>
    </head>
    <body>
        <div class="d-flex p-5 justify-content-center">
            <form method="post">
                <select name="PDF" class="selectpicker" data-size="5" data-live-search="true"  onchange="this.form.submit()">
                    <option value="">Bitte PDF auswählen...</option>
                    <?php
                        foreach($files as $file)
                        {
                    ?>
                        <option><?php echo basename($file,$dir); ?></option>
                    <?php
                        }
                    ?>
                </select>
            </form>
        </div>
<?php
if(isset($_POST["PDF"])){
  $pdf= $_POST["PDF"];
  echo $pdf;
}
?>
        <button type="button" onclick="printJS({printable:'PDF/<?php echo $pdf?>', type:'pdf', showModal:true})">
        Print PDF
        </button>
    </body>
</html>

<?php

?>

How about using the qpdf command ( download ) to decrypt it?如何使用 qpdf 命令(下载)来解密它? On Ubuntu, you can install it with sudo apt install qpdf .在 Ubuntu 上,您可以使用sudo apt install qpdf安装它。 You can decrypt a pdf file as qpdf --decrypt input.pdf --password='pass' -- out.pdf .您可以将 pdf 文件解密为qpdf --decrypt input.pdf --password='pass' -- out.pdf It can be executed from PHP by functions such as shell_exec().它可以通过诸如 shell_exec() 之类的函数从 PHP 执行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM