简体   繁体   中英

print.js password protected pdf

I try to create a frontend which shows all PDF files from a folder as dropdown. The selected PDF should be silent printed over chrome kiosk printing mode. I'm a beginner with php and javascript, but on this steps there is no problem.

The problem is, that the PDF's should be protected with a password and this makes the silent kiosk printing unpossible for me.

I need to send the password with print.js, but I don't think that there is a function in 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.

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.

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? On Ubuntu, you can install it with sudo apt install qpdf . You can decrypt a pdf file as qpdf --decrypt input.pdf --password='pass' -- out.pdf . It can be executed from PHP by functions such as shell_exec().

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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