mirror of
https://codeberg.org/SeedDMS/paperless
synced 2024-11-26 07:22:08 +00:00
convert documents to pdf when downloading and configured to do so
This commit is contained in:
parent
ce540d3e24
commit
60bbc32f04
|
@ -993,15 +993,38 @@ class SeedDMS_ExtPaperless_RestAPI_Controller { /* {{{ */
|
|||
if($document->getAccessMode($userobj) >= M_READ) {
|
||||
$lc = $document->getLatestContent();
|
||||
if($lc) {
|
||||
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);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
$filesize = filesize($dms->contentDir . $lc->getPath());
|
||||
$stream = new \Slim\Http\Stream($fh); // create a stream instance for the response body
|
||||
|
||||
return $response->withHeader('Content-Type', $lc->getMimeType())
|
||||
|
|
5
conf.php
5
conf.php
|
@ -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')),
|
||||
|
|
Loading…
Reference in New Issue
Block a user