From 274b97759f7921420dfdc01d5914269b21b3d116 Mon Sep 17 00:00:00 2001 From: Daniel Lim Date: Wed, 17 Oct 2018 11:08:28 -0400 Subject: [PATCH 1/2] pass command line args to wkhtmltopdf to enable better formatting --- src/Resume/Command/PdfCommand.php | 39 +++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/src/Resume/Command/PdfCommand.php b/src/Resume/Command/PdfCommand.php index 78c8950..a9c9370 100644 --- a/src/Resume/Command/PdfCommand.php +++ b/src/Resume/Command/PdfCommand.php @@ -31,6 +31,25 @@ class PdfCommand extends HtmlCommand InputOption::VALUE_REQUIRED, 'Which of the templates to use' ) + ->addOption( + 'htmlonly', + 'H', + InputOption::VALUE_NONE, + 'Only render interim HTML (don\'t run wkhtmltopdf)' + ) + ->addOption( + 'keephtml', + 'k', + InputOption::VALUE_NONE, + 'Keep interim HTML' + ) + ->addOption( + 'pdfargs', + 'p', + InputOption::VALUE_REQUIRED, + 'Passthrough arguments for wkhtmltopdf', + '--dpi 300 -s Letter' + ) ->addOption( 'output', 'o', @@ -48,6 +67,9 @@ class PdfCommand extends HtmlCommand $template = $input->getOption('template'); $pdfSource = join(DIRECTORY_SEPARATOR, array($destination, '.tmp_pdf_source.html')); $optFilename = $input->getOption('output'); + $htmlonly = $input->getOption('htmlonly'); + $keephtml = $input->getOption('keephtml'); + $pdfargs = $input->getOption('pdfargs'); $destFilename = join(DIRECTORY_SEPARATOR, array($destination, pathinfo($source, PATHINFO_FILENAME) . '.pdf')); @@ -82,11 +104,24 @@ class PdfCommand extends HtmlCommand // Save to a temp destination for the pdf renderer to use file_put_contents($pdfSource, $rendered); + $cmd = "wkhtmltopdf $pdfargs $pdfSource $destFilename"; + // $output->writeln($cmd); + // Process the document with wkhtmltopdf - exec('wkhtmltopdf --dpi 300 ' . $pdfSource .' ' . $destFilename); + if(!$htmlonly) + exec($cmd); // Unlink the temporary file - unlink($pdfSource); + if(!($htmlonly || $keephtml)) + unlink($pdfSource); + else + $output->writeln( + sprintf( + "Keeping interim HTML: %s", + $pdfSource + ), + $this->app->outputFormat + ); $output->writeln( sprintf( From 50e7831a08eec08f51661a4f652ed0613a09a840 Mon Sep 17 00:00:00 2001 From: Daniel Lim Date: Mon, 22 Oct 2018 09:12:11 -0400 Subject: [PATCH 2/2] removed unnecessary comment --- src/Resume/Command/PdfCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Resume/Command/PdfCommand.php b/src/Resume/Command/PdfCommand.php index a9c9370..1031368 100644 --- a/src/Resume/Command/PdfCommand.php +++ b/src/Resume/Command/PdfCommand.php @@ -104,8 +104,8 @@ class PdfCommand extends HtmlCommand // Save to a temp destination for the pdf renderer to use file_put_contents($pdfSource, $rendered); + // command that will be invoked to convert html to pdf $cmd = "wkhtmltopdf $pdfargs $pdfSource $destFilename"; - // $output->writeln($cmd); // Process the document with wkhtmltopdf if(!$htmlonly)