Created
December 13, 2018 12:37
-
-
Save michaelthieulin/839b2f96778f33f8743bb5c386d9993a to your computer and use it in GitHub Desktop.
Revisions
-
michaelthieulin created this gist
Dec 13, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,49 @@ <?php declare(strict_types=1); namespace Lib\Core\Export; use Psr\Log\LoggerInterface; use Symfony\Component\Process\Process; class PdfExport { public function run($infile, $outfile, LoggerInterface $logger): bool { $process = new Process( [ '/usr/bin/chromium-browser', '--headless', '--disable-gpu', '--disable-software-rasterizer', '--disable-dev-shm-usage', '--run-all-compositor-stages-before-draw', '--no-margins', '--no-sandbox', '--print-to-pdf=' . $outfile, $infile, ], null, null, null, null); $logger->debug('Init process to convert HTML to PDF', ['cmdline' => $process->getCommandLine()]); $process->start(); $logger->debug('Process started', ['pid' => $process->getPid()]); $process->wait(function ($type, $buffer) use ($logger) { if (Process::ERR === $type) { $logger->debug('Process stderr', ['msg' => $buffer]); } else { $logger->debug('Process stdout', ['msg' => $buffer]); } }); $logger->debug('Process exit code', ['code' => $process->getExitCode()]); $process->stop(0); $logger->debug('Process stopped'); return $process->isSuccessful(); } }