Add functioning PDF comment
This brings us to be functionally complete. The phar build is remaining.
This commit is contained in:
parent
31ce19507b
commit
4e3254ac98
|
@ -2,6 +2,7 @@ vendor
|
|||
resume/_*.md
|
||||
output/*.html
|
||||
output/*.pdf
|
||||
.tmp_pdf_source.html
|
||||
|
||||
# OSX files
|
||||
.DS_Store
|
||||
|
|
|
@ -17,7 +17,7 @@ at the [blog post for the project][blog].
|
|||
## Features
|
||||
|
||||
* Three styles to choose from: modern, blockish, unstyled
|
||||
* PDF generation via `wkhtmltopdf`
|
||||
* PDF generation via [wkhtmltopdf][wkhtmltopdf]
|
||||
* Responsive design for multiple device viewport sizes
|
||||
* Simple Markdown formatting
|
||||
* Single file deployment
|
||||
|
@ -109,3 +109,4 @@ have been added. It's a nice template, and if you are a more comfortable with ht
|
|||
[srt]: http://sampleresumetemplate.net/ "A great starting point"
|
||||
[blog]: http://there4development.com/blog/2012/12/31/markdown-resume-builder/
|
||||
[pake]: https://github.com/indeyets/pake/wiki/Installing-Pake
|
||||
[wkhtmltopdf]: https://github.com/pdfkit/pdfkit/wiki/Installing-WKHTMLTOPDF
|
||||
|
|
|
@ -54,6 +54,20 @@ class HtmlCommand extends Command
|
|||
$template = $input->getOption('template');
|
||||
$refresh = $input->getOption('refresh');
|
||||
|
||||
$rendered = $this->generateHtml($source, $template, $refesh);
|
||||
file_put_contents($destination, $rendered);
|
||||
$output->writeln(
|
||||
sprintf(
|
||||
"Wrote resume to: <info>%s</info>",
|
||||
$destination
|
||||
),
|
||||
$this->app->outputFormat
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function generateHtml($source, $template, $refresh) {
|
||||
|
||||
// Check that the source file is sane
|
||||
if (!file_exists($source)) {
|
||||
$output->writeln(
|
||||
|
@ -124,16 +138,7 @@ class HtmlCommand extends Command
|
|||
)
|
||||
);
|
||||
|
||||
// Save the fully rendered html to the final destination
|
||||
file_put_contents($destination, $rendered);
|
||||
$output->writeln(
|
||||
sprintf(
|
||||
"Wrote resume to: <info>%s</info>",
|
||||
$destination
|
||||
),
|
||||
$this->app->outputFormat
|
||||
);
|
||||
|
||||
return $rendered;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,13 +1,14 @@
|
|||
<?php
|
||||
namespace Resume\Command;
|
||||
|
||||
use Resume\Command\HtmlCommand;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
class PdfCommand extends Command
|
||||
class PdfCommand extends HtmlCommand
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
|
@ -20,9 +21,9 @@ class PdfCommand extends Command
|
|||
'Source markdown document'
|
||||
)
|
||||
->addArgument(
|
||||
'output',
|
||||
'destination',
|
||||
InputArgument::REQUIRED,
|
||||
'Output html document'
|
||||
'Output pdf document'
|
||||
)
|
||||
->addOption(
|
||||
'template',
|
||||
|
@ -34,6 +35,53 @@ class PdfCommand extends Command
|
|||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$this->app = $this->getApplication();
|
||||
$source = $input->getArgument('source');
|
||||
$destination = $input->getArgument('destination');
|
||||
$template = $input->getOption('template');
|
||||
$pdfSource = join(DIRECTORY_SEPARATOR, array(dirname($destination), '.tmp_pdf_source.html'));
|
||||
|
||||
// Make sure we've got out converter available
|
||||
exec('wkhtmltopdf -V', $results, $returnVal);
|
||||
if ($returnVal) {
|
||||
$output->writeln(
|
||||
sprintf(
|
||||
"\n<error>Error:</error> Unable to locate wkhtmltopdf.\n" .
|
||||
" Please make sure that it is installed and available in " .
|
||||
"your path. \n For installation help, please read: " .
|
||||
"https://github.com/pdfkit/pdfkit/wiki/Installing-WKHTMLTOPDF \n\n",
|
||||
$destination
|
||||
),
|
||||
$this->app->outputFormat
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
$rendered = $this->generateHtml($source, $template, false);
|
||||
|
||||
// The pdf needs some extra css rules, and so we'll add them here
|
||||
// to our html document
|
||||
// TODO: Update this with the simple DOM to add class
|
||||
$rendered = str_replace('body class=""', 'body class="pdf"', $rendered);
|
||||
|
||||
// Save to a temp destination for the pdf renderer to use
|
||||
file_put_contents($pdfSource, $rendered);
|
||||
|
||||
// Process the document with wkhtmltopdf
|
||||
exec('wkhtmltopdf ' . $pdfSource .' ' . $destination);
|
||||
|
||||
// Unlink the temporary file
|
||||
unlink($pdfSource);
|
||||
|
||||
$output->writeln(
|
||||
sprintf(
|
||||
"Wrote pdf resume to: <info>%s</info>",
|
||||
$destination
|
||||
),
|
||||
$this->app->outputFormat
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue