protected $in;
protected $html;
protected $mf;
- protected $uncompressed;
+ protected $fixed;
protected $log;
protected $common_log_pointer;
protected $pages_log_pointers;
$this->html = $this->out . '/html/';
$this->mf = $this->out . '/mf/';
$this->in = $this->out . 'original.pdf';
- $this->uncompressed = $this->out . 'uncompressed.pdf';
+ $this->fixed = $this->out . 'fixed.pdf';
$this->infos = $this->out . 'infos.txt';
if (!file_exists($this->out)) {
mkdir($this->out, 0755, true);
public function copyOriginalFromUpload($tmp_file)
{
move_uploaded_file($tmp_file, $this->in);
+ $this->fixPDF();
}
public function copyOriginalFromFile($file)
{
copy($file, $this->in);
+ $this->fixPDF();
}
- public function copyOriginalFromOlderVersion()
+ public function fixPDF()
{
- if (!file_exists($this->in)) {
- // copy('https://ws.fluidbook.com/docs/' . $this->document_id . '/original.pdf', $this->in);
+ if (file_exists($this->fixed)) {
+ unlink($this->fixed);
}
+
+ $pdftk = new cubeCommandLine('pdftk');
+ $pdftk->setPath(CONVERTER_PATH);
+ $pdftk->setArg(null, $this->in);
+ $pdftk->setArg(null, 'output');
+ $pdftk->setArg(null, $this->fixed);
+ $pdftk->execute();
+ $this->addToLog($pdftk);
+
+ if (!file_exists($this->fixed)) {
+ $pdftocairo = new cubeCommandLine('pdftocairo');
+ $pdftocairo->setPath(CONVERTER_PATH);
+ $pdftocairo->setArg(null, '-pdf');
+ $pdftocairo->setArg(null, $this->in);
+ $pdftocairo->setArg(null, $this->fixed);
+ $pdftocairo->execute();
+ $this->addToLog($pdftocairo);
+ $this->lnCrop();
+ }
+
}
public function extractFonts()
public function getInfos($in = null, $force = false)
{
if (is_null($in)) {
- $in = $this->in;
+ $in = $this->fixed;
}
if (!$force && file_exists($this->infos)) {
public function lnCrop()
{
$root = dirname($this->cropped);
- `cd $root;ln -s original.pdf crop.pdf`;
+ `cd $root;ln -s fixed.pdf crop.pdf`;
}
public function parseInfos($data)
{
$fwstk = new cubeCommandLine('fwstk.sh');
$fwstk->setPath(CONVERTER_PATH);
- $fwstk->setArg('--input ' . $this->in);
+ $fwstk->setArg('--input ' . $this->fixed);
$fwstk->setArg('--cut ' . $mode);
$fwstk->setArg('--output ' . $this->cropped);
$fwstk->execute();
{
$fwstk = new cubeCommandLine('fwstk.sh');
$fwstk->setPath(CONVERTER_PATH);
- $fwstk->setArg('--input ' . $this->in);
+ $fwstk->setArg('--input ' . $this->fixed);
$fwstk->setArg('--trim');
$fwstk->setArg('--output ' . $this->cropped);
$fwstk->execute();