diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php
index 06fa4d84f1c..74e6dca1b99 100644
--- a/htdocs/core/lib/files.lib.php
+++ b/htdocs/core/lib/files.lib.php
@@ -1823,16 +1823,19 @@ function deleteFilesIntoDatabaseIndex($dir, $file, $mode = 'uploaded')
* @param string $fileinput Input file name
* @param string $ext Format of target file (It is also extension added to file if fileoutput is not provided).
* @param string $fileoutput Output filename
+ * @param string $page Page number if we convert a PDF into png
* @return int <0 if KO, 0=Nothing done, >0 if OK
*/
-function dol_convert_file($fileinput, $ext = 'png', $fileoutput = '')
+function dol_convert_file($fileinput, $ext = 'png', $fileoutput = '', $page='')
{
global $langs;
if (class_exists('Imagick'))
{
$image=new Imagick();
try {
- $ret = $image->readImage($fileinput);
+ $filetoconvert=$fileinput.(($page != '')?'['.$page.']':'');
+ //var_dump($filetoconvert);
+ $ret = $image->readImage($filetoconvert);
} catch(Exception $e) {
$ext = pathinfo($fileinput, PATHINFO_EXTENSION);
dol_syslog("Failed to read image using Imagick (Try to install package 'apt-get install php-imagick ghostscript' and check there is no policy to disable ".$ext." convertion in /etc/ImageMagick*/policy.xml): ".$e->getMessage(), LOG_WARNING);
diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php
index bb6cc1d81d6..b67d92860d0 100644
--- a/htdocs/core/lib/functions.lib.php
+++ b/htdocs/core/lib/functions.lib.php
@@ -1386,26 +1386,28 @@ function dol_banner_tab($object, $paramid, $morehtml = '', $shownav = 1, $fieldi
$relativepath = $subdir.'/'.$objectref.'.pdf';
// Define path to preview pdf file (preview precompiled "file.ext" are "file.ext_preview.png")
- $fileimage = $file.'_preview.png'; // If PDF has 1 page
- $fileimagebis = $file.'_preview-0.png'; // If PDF has more than one page
+ $fileimage = $file.'_preview.png';
$relativepathimage = $relativepath.'_preview.png';
+ $pdfexists = file_exists($file);
+
// If PDF file exists
- if (file_exists($file))
+ if ($pdfexists)
{
// Conversion du PDF en image png si fichier png non existant
- if ( (! file_exists($fileimage) || (filemtime($fileimage) < filemtime($file)))
- && (! file_exists($fileimagebis) || (filemtime($fileimagebis) < filemtime($file)))
- )
+ if (! file_exists($fileimage) || (filemtime($fileimage) < filemtime($file)))
{
if (empty($conf->global->MAIN_DISABLE_PDF_THUMBS)) // If you experience trouble with pdf thumb generation and imagick, you can disable here.
{
include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
- $ret = dol_convert_file($file, 'png', $fileimage);
+ $ret = dol_convert_file($file, 'png', $fileimage, '0'); // Convert first page of PDF into a file _preview.png
if ($ret < 0) $error++;
}
}
+ }
+ if ($pdfexists && ! $error)
+ {
$heightforphotref=70;
if (! empty($conf->dol_optimize_smallscreen)) $heightforphotref=60;
// Si fichier png PDF d'1 page trouve
@@ -1415,14 +1417,6 @@ function dol_banner_tab($object, $paramid, $morehtml = '', $shownav = 1, $fieldi
$phototoshow.= '';
$phototoshow.= '';
}
- // Si fichier png PDF de plus d'1 page trouve
- elseif (file_exists($fileimagebis))
- {
- $preview = preg_replace('/\.png/', '', $relativepathimage) . "-0.png";
- $phototoshow = '
'; - $phototoshow.= '