return sqrt($a4surface / $docSurface);
}
- public function processUpload($uploadID)
+ public function processUpload($uploadID, $sync = false)
{
FluidbookDocumentUpload::updateProgression($uploadID, __('Analyse du document'), 1.3);
$this->checkInfos();
- FluidbookDocumentUpload::updateProgression($uploadID, __('Génération des miniatures (:done/:pages)', ['pages' => $this->pages, 'done' => 0]), 2);
+ FluidbookDocumentUpload::updateProgression($uploadID, __('Nettoyage du document'), 1.5);
+ $this->fixPDF();
+ FluidbookDocumentUpload::updateProgression($uploadID, __('Découpe du document'), 1.8);
+ $this->splitPDF();
+ FluidbookDocumentUpload::updateProgression($uploadID, __('Conversion des pages (:done/:pages)', ['pages' => $this->pages, 'done' => 0]), 2);
$jobs = [];
+
+ $files = [['jpg', 'thumb'], ['jpg', 150]];
+
for ($i = 1; $i <= $this->pages; $i++) {
- $job = new FluidbookDocumentFileProcess($this, $i, 'jpg', 'thumb');
- $job->dispatch();
- $jobs[] = $job;
+ foreach ($files as $file) {
+ $job = new FluidbookDocumentFileProcess($this, $i, $file[0], $file[1]);
+ if ($sync) {
+ dispatch_sync($job);
+ } else {
+ dispatch($job);
+ }
+ $jobs[] = $job;
+ }
}
+ $nbjobs = count($jobs);
+ $nbfiles = count($files);
+
while (true) {
$done = 0;
foreach ($jobs as $job) {
$done++;
}
}
- $progress = $done / $this->pages;
- FluidbookDocumentUpload::updateProgression($uploadID, __('Génération des miniatures (:done/:pages)', ['pages' => $this->pages, 'done' => $done]), 2 + $progress);
- usleep(0.25 * 1000000);
+ $progress = $done / $nbjobs;
+ FluidbookDocumentUpload::updateProgression($uploadID, __('Conversion des pages (:done/:pages)', ['pages' => $this->pages, 'done' => round($done / $nbfiles)]), 2 + $progress);
if ($progress === 1) {
break;
}
+ usleep(0.25 * 1000000);
}
}
public function checkInfos()
{
if (null === $this->pdf_data) {
- $infos = PDFTools::infos();
+ $infos = PDFTools::infos($this->path('original.pdf'));
$this->pages = $infos['pages'];
$this->pdf_data = $infos['infos'];
$this->bookmarks = $infos['bookmarks'];
}
}
+ public function fixPDF()
+ {
+ $fixed = $this->path('fixed.pdf');
+ $original = $this->path('original.pdf');
+ if (!file_exists($fixed) || filesize($fixed) === 0 || filemtime($fixed) < filemtime($original)) {
+ PDFTools::fixPDF($original, $fixed);
+ }
+ return $fixed;
+ }
+
+ public function splitPDF()
+ {
+ PDFTools::split($this->fixPDF(), $this->path('pdf'));
+ }
+
/**
* @return string
*/
public function hasFile($page, $format = 'jpg', $resolution = 150, $withText = true, $withGraphics = true, $version = 'html')
{
+ $this->_normalize($format, $resolution, $withText, $withGraphics, $version);
$cacheKey = $this->fileCacheKey($page, $format, $resolution, $withText, $withGraphics, $version);
if (Cache::has($cacheKey)) {
return true;
}
}
- protected function _getPath($page, $format = 'jpg', $resolution = 150, $withText = true, $withGraphics = true, $version = 'html')
+ protected function _normalize(&$format, &$resolution, &$withText, &$withGraphics, &$version)
{
- $cacheKey = $this->fileCacheKey($page, $format, $resolution, $withText, $withGraphics, $version);
- if (Cache::has($cacheKey)) {
- return Cache::get($cacheKey);
- }
-
if ($format === 'jpeg') {
$format = 'jpg';
}
$withText = true;
$version = '';
}
+ }
+
+ public function _getPath($page, $format = 'jpg', $resolution = 150, $withText = true, $withGraphics = true, $version = 'html')
+ {
+ $cacheKey = $this->fileCacheKey($page, $format, $resolution, $withText, $withGraphics, $version);
+ if (Cache::has($cacheKey)) {
+ return Cache::get($cacheKey);
+ }
+
+ $this->_normalize($format, $resolution, $withText, $withGraphics, $version);
$dir = $this->path($version) . '/';
$file .= '-' . $resolution;
}
$file .= '.svg';
-
} else if ($format === 'png' || $format === 'jpg') {
$prefix = $withText ? 't' : 'h';
if ($resolution === 'thumb') {
protected function fileCacheKey($page, $format = 'jpg', $resolution = 150, $withText = true, $withGraphics = true, $version = 'html')
{
+ $this->_normalize($format, $resolution, $withText, $withGraphics, $version);
return 'FluidbookDocument_' . $this->id . '_' . $page . '_' . $format . '_' . $resolution . '_' . ($withText ? '1' : '0') . '_' . ($withGraphics ? '1' : '0') . '_' . $version;
}
public function getFile($page, $format = 'jpg', $resolution = 150, $withText = true, $withGraphics = true, $version = 'html', $force = false)
{
+ $this->_normalize($format, $resolution, $withText, $withGraphics, $version);
if ($force) {
$this->removeFile($page, $format, $resolution, $withText, $withGraphics, $version);
}
public function _getFile($page, $format = 'jpg', $resolution = 150, $withText = true, $withGraphics = true, $version = 'html')
{
if (!$this->hasFile($page, $format, $resolution, $withText, $withGraphics, $version)) {
- return FluidbookFarm::getFile($page, $format, $resolution, $withText, $withGraphics, $version, $this->getResolutionRatio(), $this->getMobileFirstRatio(), $this->path(), $force);
+ return FluidbookFarm::getFile($page, $format, $resolution, $withText, $withGraphics, $version, $this->getResolutionRatio(), $this->getMobileFirstRatio(), $this->path() . '/');
}
$path = $this->_getPath($page, $format, $resolution, $withText, $withGraphics, $version);
var conversion = '';
var conversionOperation;
var conversionPages;
+ var progressInterval;
function initPages() {
var data = JSON.parse($("#compositionField").val());
});
$(document).on('submit', '#compositionUploadForm', function () {
$(this).ajaxSubmit({
- complete: function (data) {
- console.log(data);
+ success: function (data) {
+ var uploadID = data.uploadID;
+ progressInterval = setInterval(function () {
+ updateProgressBar(uploadID);
+ }, 250);
},
uploadProgress: function (event, position, total, percentComplete) {
- console.log(percentComplete);
+ var progress = position / total;
+ var message = '{{__('Chargement du document')}}';
+ if (progress === 1) {
+ message = '{{__('Initialisation de la conversion')}}';
+ }
+ showProgressBar(message, progress);
},
error: function (data) {
new Noty({
});
}
+ function updateProgressBar(uploadID) {
+ $.ajax({
+ url: '{{backpack_url($entry->getOption('name').'/uploadProgress')}}' + '/' + uploadID,
+ success: function (data) {
+ showProgressBar(data.message, data.progress);
+ }
+ })
+ }
+
+ function showProgressBar(message, progress) {
+ console.log(message, progress);
+ if(progress===3){
+ hideProgressBar();
+ }
+ }
+
+ function hideProgressBar(){
+ clearInterval(progressInterval);
+ console.log('End conversion');
+ }
+
function updateComposition() {
var res = {};
var numbers = [];