use Exception;
use Fluidbook\Tools\Jobs\ProcessFile;
use Fluidbook\Tools\Jobs\ProcessPage;
+use Fluidbook\Tools\PDF\Document;
use Fluidbook\Tools\Search\SearchIndex;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
public function addSource($document, $start = 1, $pages = null)
{
- $source = new Source($document,$this, $start );
+ $source = new Source(new Document($document), $start, $pages);
$this->sources[] = $source;
foreach ($source->getRange() as $sourcePage) {
$this->pages[] = new SourcePage($source, $sourcePage);
{
start_measure('Process Pages');
foreach ($this->sources as $source) {
+ dd( $source->getRange());
$source->getDocument()->processPages($this->getProcessFiles(), $source->getRange(), $sync);
}
stop_measure('Process Pages');
namespace Fluidbook\Tools\Jobs;
use Cubist\Util\Files\Files;
-use Fluidbook\Tools\Compiler\SourcePage;
use Fluidbook\Tools\PDF\Document;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
- * @var ProcessFile[]
+ * @var Document
*/
- protected $files = [];
+ protected $document;
+
+ /**
+ * @var integer
+ */
+ protected $page;
/**
- * @var SourcePage
+ * @var ProcessFile[]
*/
- protected $source;
+ protected $files = [];
/**
- * @param $source SourcePage
+ * @param $document Document
+ * @param $page integer
* @param ProcessFile[] $files
*/
- public function __construct($source, $files = [])
+ public function __construct($document, $page, $files = [])
{
- $this->source = $source;
+ $this->document = $document;
+ $this->page = $page;
$this->files = $files;
}
+ /**
+ * @param int $page
+ */
+ public function setPage(int $page): void
+ {
+ $this->page = $page;
+ }
+
/**
* @return int
*/
public function getPage(): int
{
- return $this->source->getPage();
+ return $this->page;
+ }
+
+ /**
+ * @return string
+ */
+ public function getOut(): string
+ {
+ return $this->document->getConvertPath();
}
public function handle()
{
- start_measure('Process page ' . $this->source->getPage());
+ start_measure('Process page ' . $this->page);
foreach ($this->files as $file) {
- $this->getFile($file, false);
+ $this->getFile($this->page, $file, false);
}
- stop_measure('Process page ' . $this->source->getPage());
+ stop_measure('Process page ' . $this->page);
}
/**
- * @p
+ * @param $page
* @param $file ProcessFile
* @param false $force
* @return string
*/
- public function getFile($file, $force = false)
+ public function getFile($page, $file, $force = false)
{
+ $this->setPage($page);
$file->setJob($this);
return $file->getPath($force);
}
public function getResolutionRatio()
{
- return $this->source->getSource()->getDocument()->getResolutionRatio();
+ return $this->document->getResolutionRatio();
}
public function getMobileFirstRatio()
{
- return $this->source->getSource()->getDocument()->getMobileFirstRatio();
+ return $this->document->getMobileFirstRatio();
}
public function splitDoc()
{
start_measure('Split PDF');
- Files::mkdir($this->out . '/pdf');
+ Files::mkdir($this->getOut() . '/pdf');
$pdftk = new CommandLine('pdftk');
$pdftk->setArg(null, $this->getPDFInput());
$pdftk->setArg(null, 'burst');
$pdftk->setArg(null, 'uncompress');
$pdftk->setArg(null, 'output');
- $pdftk->setArg(null, $this->out . 'pdf/p%d.pdf');
+ $pdftk->setArg(null, $this->getOut() . 'pdf/p%d.pdf');
$pdftk->execute();
for ($i = 1; $i <= $this->getPagesNumber(); $i++) {
// Remove annotations : https://gist.github.com/stefanschmidt/5248592
- $file = sprintf($this->out . 'pdf/p%d.pdf', $i);
- $to = sprintf($this->out . 'pdf/s%d.pdf', $i);
+ $file = sprintf($this->getOut() . 'pdf/p%d.pdf', $i);
+ $to = sprintf($this->getOut() . 'pdf/s%d.pdf', $i);
`LANG=C LC_CTYPE=C sed -n '/^\/Annots/!p' $file > $to`;
if (file_exists($to)) {
if (filesize($to) > 0) {
*/
public function getPagesNumber()
{
- return $this->source->getSource()->getDocument()->getPages();
+ return $this->document->getPages();
}
public function getPDFInput()
{
- return $this->source->getSource()->getDocument()->getPDFInput();
- }
-
- /**
- * @return SourcePage
- */
- public function getSource(): SourcePage
- {
- return $this->source;
+ return $this->document->getPDFInput();
}
}
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;
use Fluidbook\Tools\Jobs\ProcessPage;
return $this->hash;
}
- public function getConvertPath()
+ public function getConvertPath(): string
{
return storage_path('fluidbook/convert/' . $this->getHash() . '/');
}
$infos = $fwstk->getOutput();
-
if (preg_match('/Pages:\s*(\d+)/', $infos, $matches)) {
$this->pages = (int)$matches[1];
}
public function processPage($page, $files, $sync = false)
{
$dispatchFunction = $sync ? 'dispatchSync' : 'dispatch';
- ProcessPage::$dispatchFunction($this, $page, $this->getConvertPath(), $files);
+ ProcessPage::$dispatchFunction($this, $page, $files);
}
public function processLinks()