Siddharajsinh Zala
Siddharajsinh Zala

Reputation: 71

How to create each page as PDF from existing PDF using mPDF in Laravel

use ZanySoft\LaravelPDF\PDF;

$mpdf = new PDF();
$mpdf->SetImportUse();

$pagecount = $mpdf->SetSourceFile(storage_path() . '/app/public/applications/test.pdf');

// test.pdf have 2 pages $pagecount have value 2.

for($i=1; $i <= $pagecount ; $i++) {
   $tplId = $mpdf->ImportPage($i);          
   $mpdf->addPage();
   $mpdf->UseTemplate($tplId);
   // store each page as pdf file
   $new_file_name = "new-".$i.".pdf";
   $mpdf->Output($new_file_name, \Mpdf\Output\Destination::FILE);
}

I am getting an error Class 'Mpdf\Output\Destination' not found. I have tried below things as second argument of Output();

  1. $mpdf->Output($new_file_name, \PDF\Output\Destination::FILE);
  2. $mpdf->Output($new_file_name, \Mpdf\Mpdf\Output\Destination::FILE);

But, it is not working. Please help to store fetch page store as PDF file direct on directory.

Upvotes: 0

Views: 601

Answers (1)

Finwe
Finwe

Reputation: 6755

ZanySoft\LaravelPDF\PDF uses mPDF in version 6.1 which does not have output destination class constants yet.

Use a plain string:

$mpdf->Output($new_file_name, 'F');

Or use composer package mpdf/mpdf in version >=7 directly.

Upvotes: 1

Related Questions