convert documents to pdf when downloading and configured to do so

This commit is contained in:
Uwe Steinmann 2023-09-06 15:11:20 +02:00
parent ce540d3e24
commit 60bbc32f04
2 changed files with 36 additions and 8 deletions

View File

@ -993,15 +993,38 @@ class SeedDMS_ExtPaperless_RestAPI_Controller { /* {{{ */
if($document->getAccessMode($userobj) >= M_READ) {
$lc = $document->getLatestContent();
if($lc) {
if(empty($settings->_extensions['paperless']['converttopdf']) || $lc->getMimeType() == 'application/pdf') {
if (pathinfo($document->getName(), PATHINFO_EXTENSION) == $lc->getFileType())
$filename = $document->getName();
else
$filename = $document->getName().$lc->getFileType();
$file = $dms->contentDir . $lc->getPath();
if(!($fh = @fopen($file, 'rb'))) {
return $response->withJson(array('success'=>false, 'message'=>'', 'data'=>''), 500);
}
$filesize = filesize($dms->contentDir . $lc->getPath());
} else {
$previewer = new SeedDMS_Preview_PdfPreviewer($settings->_cacheDir);
if($conversionmgr)
$previewer->setConversionMgr($conversionmgr);
else
$previewer->setConverters(isset($settings->_converters['pdf']) ? $settings->_converters['pdf'] : array());
if(!$previewer->hasPreview($lc))
$previewer->createPreview($lc);
if(!$previewer->hasPreview($lc)) {
$logger->log('Creating pdf preview failed', PEAR_LOG_ERR);
return $response->withJson('', 500);
} else {
$filename = $document->getName().".pdf";
$file = $previewer->getFileName($lc).".pdf";
$filesize = filesize($file);
if(!($fh = @fopen($file, 'rb'))) {
$logger->log('Creating pdf preview failed', PEAR_LOG_ERR);
return $response->withJson('', 500);
}
}
}
$stream = new \Slim\Http\Stream($fh); // create a stream instance for the response body
return $response->withHeader('Content-Type', $lc->getMimeType())

View File

@ -66,6 +66,11 @@ $EXT_CONF['paperless'] = array(
'objtype'=>'2',
'allow_empty'=>true,
),
'converttopdf' => array(
'title'=>'Convert to PDF',
'type'=>'checkbox',
'help'=>"Enable, if you want non pdf documents to be converted to PDF if they are downloaded. Usually, this is only done for preview.",
),
),
'constraints' => array(
'depends' => array('php' => '7.4.0-', 'seeddms' => array('5.1.31-5.1.99', '6.0.24-6.0.99')),