0

I am using dompdf to generate invoices, one invoice is generated but I want to generate 3 copies of same invoice pdf file which is copy1, copy2, copy3. Each copy should start on new page of the same pdf file.

$dompdf = PDF::loadView('admin.pdf.invoice', compact('data'));
$options = [];
$options['isHtml5ParserEnabled'] = true;
$options['isRemoteEnabled'] = true;
$options['isPhpEnabled'] = true;
$dompdf->setOptions($options);
$dompdf->setPaper('A4', 'portrait');
$file =LOCAL_PDF_PATH."invoice.pdf";
$dompdf->save(LOCAL_PDF_PATH."invoice.pdf");
koen
  • 5,383
  • 7
  • 50
  • 89
shweta
  • 11
  • 4
  • So would a [file copy](https://www.php.net/manual/en/function.copy.php) do the trick for you? – RiggsFolly Sep 24 '19 at 12:13
  • 2
    `$dompdf->save(LOCAL_PDF_PATH."invoice1.pdf"); $dompdf->save(LOCAL_PDF_PATH."invoice2.pdf"); $dompdf->save(LOCAL_PDF_PATH."invoice3.pdf");` ? – Frankich Sep 24 '19 at 12:15
  • Since the OP add a comment to clarify that he would like to have all the copy in the same file, then : https://stackoverflow.com/questions/22746958/dompdf-adding-a-new-page-to-pdf . and just triple your duplicate your `loadView` 3 times ? – Frankich Sep 24 '19 at 12:33

2 Answers2

0

Try this code

for($i=0;$i<3;$i++){
    $dompdf = PDF::loadView('admin.pdf.invoice', compact('data'));
    $options = [];
    $options['isHtml5ParserEnabled'] = true;
    $options['isRemoteEnabled'] = true;
    $options['isPhpEnabled'] = true;
    $dompdf->setOptions($options);
    $dompdf->setPaper('A4', 'portrait');
    $file =LOCAL_PDF_PATH."invoice.pdf";
    $dompdf->save(LOCAL_PDF_PATH."invoice".$i.".pdf"); 
}
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
  • But i want all copies in one pdf file, every copy should be start with new page and each of them should have name like for receipient,for transportor and one for supplier – shweta Sep 24 '19 at 12:25
0

Use array chunk for that inside your view

$columns = 3; // number of columns on a page
// calculate number of rows and break the data into chunks
$num_rows = ceil(count($data) / $columns);
$data = array_chunk($data,$num_rows);