diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 3367b9bae57..f1c67429d95 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -1382,25 +1382,25 @@ function dol_banner_tab($object, $paramid, $morehtml = '', $shownav = 1, $fieldi $filepath = $dir_output . $subdir . "/"; - $file = $filepath . $objectref . ".pdf"; + $filepdf = $filepath . $objectref . ".pdf"; $relativepath = $subdir.'/'.$objectref.'.pdf'; // Define path to preview pdf file (preview precompiled "file.ext" are "file.ext_preview.png") - $fileimage = $file.'_preview.png'; + $fileimage = $filepdf.'_preview.png'; $relativepathimage = $relativepath.'_preview.png'; - $pdfexists = file_exists($file); + $pdfexists = file_exists($filepdf); // If PDF file exists if ($pdfexists) { // Conversion du PDF en image png si fichier png non existant - if (! file_exists($fileimage) || (filemtime($fileimage) < filemtime($file))) + if (! file_exists($fileimage) || (filemtime($fileimage) < filemtime($filepdf))) { 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, '0'); // Convert first page of PDF into a file _preview.png + $ret = dol_convert_file($filepdf, 'png', $fileimage, '0'); // Convert first page of PDF into a file _preview.png if ($ret < 0) $error++; } } diff --git a/htdocs/core/lib/images.lib.php b/htdocs/core/lib/images.lib.php index 583167750eb..2f7406bbaf9 100644 --- a/htdocs/core/lib/images.lib.php +++ b/htdocs/core/lib/images.lib.php @@ -33,7 +33,7 @@ $quality = 80; * Return if a filename is file name of a supported image format * * @param string $file Filename - * @return int -1=Not image filename, 0=Image filename but format not supported by PHP, 1=Image filename with format supported + * @return int -1=Not image filename, 0=Image filename but format not supported by PHP, 1=Image filename with format supported by this PHP */ function image_format_supported($file) { diff --git a/htdocs/expensereport/card.php b/htdocs/expensereport/card.php index 09c536ecaa2..a70c5159370 100644 --- a/htdocs/expensereport/card.php +++ b/htdocs/expensereport/card.php @@ -2361,8 +2361,7 @@ else $fileinfo = pathinfo($file['name']); if (image_format_supported($file['name']) > 0) { - $minifile=getImageFileNameForSize($file['name'], '_mini'); // For new thumbs using same ext (in lower case howerver) than original - //if (! dol_is_file($file['path'].'/'.$minifile)) $minifile=getImageFileNameForSize($file['name'], '_mini', '.png'); // For backward compatibility of old thumbs that were created with filename in lower case and with .png extension + $minifile=getImageFileNameForSize($file['name'], '_mini'); // For new thumbs using same ext (in lower case however) than original //print $file['path'].'/'.$minifile.'
'; $urlforhref=getAdvancedPreviewUrl($modulepart, $fileinfo['relativename'].'.'.strtolower($fileinfo['extension']), 1, '&entity='.(!empty($object->entity)?$object->entity:$conf->entity)); if (empty($urlforhref)) { @@ -2378,9 +2377,50 @@ else } else { + $modulepart='expensereport'; + //$conf->global->MAIN_DISABLE_PDF_THUMBS=1; + print '
'; - //print ''; - print img_mime($relativepath.$minifile); + $thumbshown=0; + if (preg_match('/\.pdf$/i', $file['name'])) + { + $filepdf = $conf->expensereport->dir_output.'/'.$relativepath.$file['name']; + $fileimage = $conf->expensereport->dir_output.'/'.$relativepath.$file['name'].'_preview.png'; + $relativepathimage = $relativepath.$file['name'].'_preview.png'; + + $pdfexists = file_exists($filepdf); + + if ($pdfexists) + { + // Conversion du PDF en image png si fichier png non existant + if (! file_exists($fileimage) || (filemtime($fileimage) < filemtime($filepdf))) + { + 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($filepdf, '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; + // If the preview file is found + if (file_exists($fileimage)) + { + $thumbshown=1; + print ''; + } + } + } + + if (! $thumbshown) + { + print img_mime($minifile); + } print '
'; } print '
';