DomPDF - Block printing and download

1

Is it possible to block printing and download in DomPDF?

    
asked by anonymous 31.03.2017 / 02:48

1 answer

1

You can not prevent download permanently, what you can do is at the very most difficult, as per SOen and in Google Group

You can use CPDF to specify what the user can do with the document.

  

link

According to the CPDF documentation:

Calling the setEncryption() function will allow you to encrypt the file , the user will not be able to use copy, modify, or print (this is not the case with most popular PDF readers such as Adobe Reader, Foxit, and the Chrome native).

$cpdf = $dompdf->get_canvas()->get_cpdf();
$cpdf->setEncryption('', '', array('copy', 'print'));

If you want to configure:

$cpdf = $dompdf->get_canvas()->get_cpdf();
$cpdf->setEncryption('usuário', 'senha', array('copy', 'print'));

It is not possible to block the download, everything we browse even if the download does not actually download was actually downloaded to your machine when rendering or before rendering, you may have an automatic download problem, this is the default to disable you can adjust the parameters, using 'Attachment' => 0 , like this:

  • Version 0.7

    <?php
    use Dompdf\Dompdf;
    
    require 'vendor/autoload.php';
    
    $dompdf = new Dompdf();
    $dompdf->loadHtml('<strong>Stack</strong> Overflow');
    
    $dompdf->render();
    
    $dompdf->stream('document.pdf', array( 'Attachment' => 0 ));
    
    //Pra prevenir espaçamentos no final
    exit;
    
  • Version 0.6 or older

    <?php
    
    require_once 'dompdf_config.inc.php';
    
    $dompdf = new Dompdf();
    $dompdf->load_html('<strong>Stack</strong> Overflow');
    
    $dompdf->render();
    
    $dompdf->stream('document.pdf', array( 'Attachment' => 0 ));
    
    //Pra prevenir espaçamentos no final
    exit;
    

Still if your problem is the Ctrl + S keyboard there is not much to do at most to try to avoid I would say the recommended to just hamper would be to create a page with the PDF using iframe and the hash #toolbar=0 for example:

<!DOCTYPE html>
<html>
<head>
    <style type="text/css">
    *, html, body, .pdf {
        width: 100%;
        height: 100%;
        overflow: hidden;
        border: none;
        margin: 0;
        padding: 0;
    }
    </style>
</head>
<body>
    <iframe src="pdf.pdf#toolbar=0" class="pdf"></iframe>
</body>
</html>

This will disable the toolbar, which helps a bit, not least in the most used PDF readers, such as Adobe Reader, Foxit and the Chrome native with said earlier.

    
31.03.2017 / 04:07