#!/usr/bin/env php
<?php
require(__DIR__.'/../vendor/autoload.php');
use League\CommonMark\CommonMarkConverter;
use Spipu\Html2Pdf\Html2Pdf;
$file = getcwd().'/'.$argv[1];
if (!file_exists($file)){
echo "\nFile '$file' does not exist.";
return;
}
if (!is_file($file)){
echo "\nFile '$file' is not a file. may be a directory.";
return;
}
$content = file_get_contents($file);
// so new lines are rendered as new lines
$content = str_replace(["\r\n","\n"], " \n", $content);
$converter = new CommonMarkConverter();
$html = $converter->convertToHtml($content);
$html_for_viewing =
'<div style="width:8.5in; padding:0.3in 0.5in; box-sizing:border-box;">'
.$html
.'</div>';
file_put_contents($file.'.html', $html_for_viewing);
$name = substr($file, 0, strrpos($file, '.'));
$html2pdf = new Html2Pdf();
$html2pdf->writeHTML($html);
$html2pdf->output($name.'.pdf', 'F');
// <h1>Hello World!</h1>