0

If i have some PDF files, each has one page and i would like to merge all files into on single file using PHP

I have read dozens of questions here about same but most of all are out of date or no longer working since for PHP version >= 7.0

One of the solutions was to use PDFMerger and here is my code

require_once ('PDFMerger.php');

use PDFMerger\PDFMerger;
$pdf = new PDFMerger;

$pdf->addPDF('books/1.pdf');
$pdf->addPDF('books/2.pdf');

$pdf->merge('download','books/merged.pdf');

but if simply gives blank page and no file is created and same to this library PDFMerger

UPDATE1! wihtout namespace use PDFMerger\PDFMerger; iam getting this error

 Fatal error: Uncaught Error: Class "PDFMerger" not found in mypath\sample.php:4 Stack trace: #0 {main} thrown in mypath\sample.php on line 4

so is there any way that is still working to merger PDF files without have to care how such file are created.

NOTE! I can not use shell_exec since files are on shared hosting

Reham Fahmy
  • 4,937
  • 15
  • 50
  • 71
  • 1
    Can you try removing the file path? As you do not need to give a file path for browser, string, or download options - just the name is needed. Check [here](https://github.com/myokyawhtun/PDFMerger/blob/master/sample.php#L12) – Salvino D'sa Dec 12 '21 at 06:27

1 Answers1

0

After trying a lot of time , i decide to shift back to a lower PHP version 7.1 rather than 8.0 and everything goes fine though

Reham Fahmy
  • 4,937
  • 15
  • 50
  • 71