Skip to content

Instantly share code, notes, and snippets.

@rmcdaniel
Created December 6, 2022 02:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rmcdaniel/a8cf05d95a9d263e9a2ba58535d8d860 to your computer and use it in GitHub Desktop.
Save rmcdaniel/a8cf05d95a9d263e9a2ba58535d8d860 to your computer and use it in GitHub Desktop.
<?php
namespace App\Workflows\BuildPDF;
use setasign\Fpdi\Fpdi;
use Workflow\Activity;
class MergePDFActivity extends Activity
{
public function execute($pages)
{
$fileName = uniqid() . '.pdf';
$pdf = new Fpdi();
foreach ($pages as $page) {
$pdf->AddPage();
$pdf->setSourceFile(storage_path($page));
$pdf->useTemplate($pdf->importPage(1));
}
$pdf->Output('F', storage_path($fileName));
foreach ($pages as $page) {
unlink(storage_path($page));
}
return $fileName;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment