public function fixPDF()
{
- $fixed = $this->getPDFSource('fixed');
+ $fixed = $this->getPDFSource('fixed',false);
$original = $this->getPDFSource('original');
if (!file_exists($fixed) || filesize($fixed) === 0 || filemtime($fixed) < filemtime($original)) {
PDFTools::fixPDF($original, $fixed);
$path = $this->_getTextPath($page, $type, $mode, $extractionMethod, $ignoreSeparators);
if (!$this->_checkTextFile($path)) {
PDFTools::extractTexts($this->getPDFSource(), $this->path(), $mode, $extractionMethod, $ignoreSeparators);
- if (!Gzip::file_exists($path)) {
- throw new \Exception('An error occured while producing file ' . $path);
- }
}
return Gzip::path($path);
}
return $this->path('texts/' . $dir . $sepFolder) . $prefix . $type . $page . '.txt';
}
- public function getPDFSource($type = 'crop'): string
+ public function getPDFSource($type = 'crop', $checkIfExists = true): string
{
- return $this->path() . $type . '.pdf';
+ $res = $this->path() . $type . '.pdf';
+ if ($checkIfExists && !file_exists($res)) {
+ if ($type === 'original') {
+ throw new \Exception('Missing original PDF file ' . $res);
+ } else if ($type === 'fixed') {
+ $this->fixPDF();
+ } else if ($type === 'crop') {
+ $this->cropAndCut();
+ }
+ }
+ return $res;
}
public function cutDocument($mode)
$fwstk = new FWSTK();
$fwstk->setArg('--input ' . $this->getPDFSource('fixed'));
$fwstk->setArg('--cut ' . $mode);
- $fwstk->setArg('--output ' . $this->getPDFSource());
+ $fwstk->setArg('--output ' . $this->getPDFSource('crop', false));
$fwstk->execute();
}
$fwstk = new FWSTK();
$fwstk->setArg('--input ' . $this->getPDFSource('fixed'));
$fwstk->setArg('--trim');
- $fwstk->setArg('--output ' . $this->getPDFSource());
+ $fwstk->setArg('--output ' . $this->getPDFSource('crop', false));
$fwstk->execute();
}
public function lnCrop()
{
- link($this->getPDFSource('fixed'), $this->getPDFSource());
+ link($this->getPDFSource('fixed'), $this->getPDFSource('crop', false));
}
protected function isCropped()
'searchLogic' => false,
'can' => 'fluidbook-publication:admin',
]);
-
+
$this->addField('section_composition', FormBigSection::class, __('Composition'));
$this->addField('composition_fluidbook', Checkbox::class, __('Utiliser la composition d\'un autre fluidbook'), ['default' => false]);
$this->addField('composition_fluidbook_id', FluidbookV3ID::class, __('Utiliser la composition d\'un autre fluidbook'), ['excluded_options' => $this->id, 'when' => ['composition_fluidbook' => 1]]);
return $this->composition_updated_at->getTimestamp();
}
- public function getPDFSource($page, $type = 'crop'): string
+ public function getPDFSource($page, $type = 'crop', $checkIfExist = true): string
{
$compo = $this->getComposition()[$page];
if ($type == 'crop') {
- return self::_getDocument($compo[0])->getPDFSource($type);
+ return self::_getDocument($compo[0])->getPDFSource($type, $checkIfExist);
}
}