Is there a way to disable copy and paste of the document generated using DOMPDF in PHP?
I like to generate a pdf in my website and I also like to prevent the users to copy and paste the content. Is that possible with the dompdf library?
For DOMPDF, to prevent the resulting pdf from copying (copy and paste), just use setEncryption
without the parameters
So the code (I have tested, 100% work) is:
<?php
require_once 'vendor/autoload.php';
// reference the Dompdf namespace
use Dompdf\Dompdf;
// instantiate and use the dompdf class
$dompdf = new Dompdf();
$dompdf->loadHtml('hello world');
// (Optional) Setup the paper size and orientation
$dompdf->setPaper('A4', 'landscape');
// Render the HTML as PDF
$dompdf->render();
$dompdf->get_canvas()->get_cpdf()->setEncryption();
// Output the generated PDF to Browser
$dompdf->stream('output.pdf');
?>