public function setJob(ProcessPage $job)
{
$this->job = $job;
+ return $this;
}
public function getPath($force = false)
$res = $dir . 'p' . $this->getPage() . '.' . $this->getFormat();
} else {
$res = $dir . $prefix . $this->getPage() . '-' . $this->getResolution() . '.' . $this->getFormat();
- $alt = $dir . $prefix . $this->getResolution() . '-' . $this->getPage() . '.' . $this->getFormat();
}
} else if ($this->getFormat() === 'swf') {
$res = $dir . 'p' . $this->getPage() . '.' . $this->getFormat();
}
$do = false;
- if (!file_exists($res)) {
- if (isset($alt) && file_exists($alt) && filesize($alt) > $minsize) {
- rename($alt, $res);
- $do = false;
- } else {
- $do = true;
- }
- } else if (filesize($res) < $minsize) {
+ if (!file_exists($res) || filesize($res) < $minsize) {
$do = true;
} else if (isset($reffile) && filemtime($res) < filemtime($reffile)) {
$do = true;
- } else if ($this->getFormat() === 'svg') {
- $t = filemtime($res);
- $do = $t < 1603181003 && $t > 1602662603;
}
if ($do || $force) {
PDFTools::makeSWF($this->getSplittedPDFPage(), $file, 1, $this->getResolution(), 80);
}
unlink($lock);
+ if (!file_exists($file)) {
+ throw new \Exception(sprintf('Failed to generate %s', $file));
+ }
}
public function makeSVGFile($force = false)
namespace Fluidbook\Tools\PDF;
use Cubist\Util\CommandLine;
+use Cubist\Util\Text;
use Fluidbook\Tools\CommandLine\FWSTK;
use Fluidbook\Tools\FluidbookTools;
use Fluidbook\Tools\Jobs\ProcessFile;
*/
protected $height;
+ /**
+ * @var array
+ */
+ protected $pageNumbers = [];
+
+ /**
+ * @var array
+ */
+ protected $chapters = [];
+
public function __construct($in)
{
$this->in = $in;
$infos = $fwstk->getOutput();
+
if (preg_match('/Pages:\s*(\d+)/', $infos, $matches)) {
$this->pages = (int)$matches[1];
}
$this->width = (float)$matches[1];
$this->height = (float)$matches[2];
}
+
+ if (preg_match('/NumberSections:\s*(.*)/', $infos, $matches)) {
+ $this->pageNumbers = explode(',', $matches[1]);
+ } else {
+ $this->pageNumbers = range(1, $this->pages);
+ }
+
+ $lines = Text::explodeNewLines($infos);
+ $bookmark_id = -1;
+
+
+ foreach ($lines as $line) {
+ $line = trim($line);
+ [$k, $v] = explode(':', $line);
+ $k = trim($k);
+ $v = trim($v);
+
+ if ($k === 'BookmarkTitle') {
+ $bookmark_id++;
+ $this->chapters[$bookmark_id] = array('label' => str_replace(' ', '', $v));
+ } elseif ($k === 'BookmarkLevel') {
+ $this->chapters[$bookmark_id]['level'] = (int)$v - 1;
+ } elseif ($k === 'BookmarkPage') {
+ $this->chapters[$bookmark_id]['page'] = $v;
+ }
+ }
}
/**
stop_measure('Compile search index');
}
- public function compileSearchIndex($dest){
+ public function getPageNumbers()
+ {
+ $this->getInfos();
+ return $this->pageNumbers;
+ }
+
+ public function getChapters()
+ {
+ $this->getInfos();
+ return $this->chapters;
+ }
+
+ public function compileSearchIndex($dest)
+ {
}
+
public function getResolutionRatio()
{
$a4surface = 500990; // en pt²