0

I have pdf files. Need import them to system and split by pages. Seperate page = separate file.

I tried use FPDF and FPDI:

  $pdf = new FPDI(); //FPDI extends TCPDF
  $pdf->AddPage();
  $pages = $pdf->setSourceFile($sLeadDirPath . $sImageName);
  //for first page...
  $page = $pdf->ImportPage(1);
  $pdf->useTemplate($page, 0, 0);
  $pdf->Output('newTest.pdf', 'F');    

Some files work good, but for some files i got error:

Fatal error: Uncaught exception 'setasign\Fpdi\PdfParser\CrossReference\CrossReferenceException' with message 'This PDF document is encrypted and cannot be processed with FPDI.'

As I understood file is encrypted (but i can open this without any problems). How can I solve this?

Or maybe there are other ways for split pdf in PHP without FPDI?

Thanks!

ncica
  • 7,015
  • 1
  • 15
  • 37

1 Answers1

1

A PDF can be encrypted even though you are not required to enter a password to see the contents of the document. This can be the case when the PDF file does not have an 'document open password' (user password) but has a 'permissions password' (master password). When this is the case, you will be able to open the PDF without entering a password, but you will not be able to edit the PDF (manually or through FPDI) without entering that password. You will have to decrypt the PDF, however, this is not implemented in FPDI:

FPDI does not support importing of encrytped [sic] PDF documents. After all this makes no sense, because the resulting document is a completely new document which may be re-encrypted or not.

(...)

If you need to modify an existing document, that is already encrypted you may checkout any SetaPDF product.

Tom Udding
  • 2,264
  • 3
  • 20
  • 30