mirror of
https://codeberg.org/SeedDMS/paperless
synced 2025-05-14 21:51:30 +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) {
|
if($document->getAccessMode($userobj) >= M_READ) {
|
||||||
$lc = $document->getLatestContent();
|
$lc = $document->getLatestContent();
|
||||||
if($lc) {
|
if($lc) {
|
||||||
if (pathinfo($document->getName(), PATHINFO_EXTENSION) == $lc->getFileType())
|
if(empty($settings->_extensions['paperless']['converttopdf']) || $lc->getMimeType() == 'application/pdf') {
|
||||||
$filename = $document->getName();
|
if (pathinfo($document->getName(), PATHINFO_EXTENSION) == $lc->getFileType())
|
||||||
else
|
$filename = $document->getName();
|
||||||
$filename = $document->getName().$lc->getFileType();
|
else
|
||||||
$file = $dms->contentDir . $lc->getPath();
|
$filename = $document->getName().$lc->getFileType();
|
||||||
if(!($fh = @fopen($file, 'rb'))) {
|
$file = $dms->contentDir . $lc->getPath();
|
||||||
return $response->withJson(array('success'=>false, 'message'=>'', 'data'=>''), 500);
|
|
||||||
|
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
|
$stream = new \Slim\Http\Stream($fh); // create a stream instance for the response body
|
||||||
|
|
||||||
return $response->withHeader('Content-Type', $lc->getMimeType())
|
return $response->withHeader('Content-Type', $lc->getMimeType())
|
||||||
|
|
5
conf.php
5
conf.php
|
@ -66,6 +66,11 @@ $EXT_CONF['paperless'] = array(
|
||||||
'objtype'=>'2',
|
'objtype'=>'2',
|
||||||
'allow_empty'=>true,
|
'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(
|
'constraints' => array(
|
||||||
'depends' => array('php' => '7.4.0-', 'seeddms' => array('5.1.31-5.1.99', '6.0.24-6.0.99')),
|
'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