I am trying to generate a PDF using TCPDF/TCPDI but then flatten the PDF to become an image-based pdf. The result would be the PDF would not be selectable and ideally would be to stop Adobe allowing text editing.
From what I have read, it isn't something that is possible with just TCPDF however, I have recently come across a website that does exactly this and states it was generated by FPDF.
I have managed to get the results by passing it through TCPDF, then using Ghostscript pdfimage24 afterwards.
$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdfdata = file_get_contents('docs/original.pdf');
$pagecount = $pdf->setSourceData($pdfdata);
for ($i = 1; $i <= $pagecount; $i++) {
$tplidx = $pdf->importPage($i);
$pdf->AddPage();
$pdf->useTemplate($tplidx);
// PDF INFO TO MERGE HERE
}
$pdf_out = $pdf->Output($before, 'F');
exec('gs -q -dNOPAUSE -sDEVICE=pdfimage24 -r300 -dDownScaleFactor=3 -sOutputFile=docs/after.pdf docs/before.pdf -c quit');
As I am new to PHP, my question would be is this the right away to go about this, could this way hard on performance and is there any way of getting the result in TCPDF which is based on FPDF to flatten an image in this way.
Thanks in advance.