mirror of
https://github.com/there4/markdown-resume.git
synced 2024-12-03 08:59:35 -05:00
Add functioning PDF comment
This brings us to be functionally complete. The phar build is remaining.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user