Commit a40e347e authored by Carsten  Rose's avatar Carsten Rose

Refs #10358 - qpdf, gs, pdfunite might be configured via QFQ config

parent 2a97a37c
Pipeline #3394 passed with stages
in 4 minutes and 56 seconds
......@@ -59,6 +59,7 @@ plantuml:
bootstrap: .npmpackages .plantuml_install .virtual_env
npm update
grunt default
# take care that phpOffice is located under 'qfq/Resources/Private/vendor/phpoffice'
# cd extension/Resources/Private; composer update
cd extension; composer update
......
......@@ -644,10 +644,13 @@ const SYSTEM_ENTER_AS_SUBMIT = 'enterAsSubmit';
const SYSTEM_SHOW_ID_IN_FORM_TITLE = 'showIdInFormTitle';
const SYSTEM_CMD_WKHTMLTOPDF = 'cmdWkhtmltopdf';
// Thumbnail
const SYSTEM_CMD_INKSCAPE = 'cmdInkscape';
const SYSTEM_CMD_CONVERT = 'cmdConvert';
const SYSTEM_CMD_QPDF = 'cmdQpdf';
const SYSTEM_CMD_GS = 'cmdGs';
const SYSTEM_CMD_PDFUNITE = 'cmdPdfunite';
// Thumbnail
const SYSTEM_THUMBNAIL_DIR_SECURE = 'thumbnailDirSecure';
const SYSTEM_THUMBNAIL_DIR_SECURE_DEFAULT = 'fileadmin/protected/qfqThumbnail';
const SYSTEM_THUMBNAIL_DIR_PUBLIC = 'thumbnailDirPublic';
......
......@@ -63,6 +63,21 @@ class Download {
*/
private $downloadDebugLog = '';
/**
* @var string Name of command
*/
private $qpdf = '';
/**
* @var string Name of command
*/
private $gs = '';
/**
* @var string Name of command
*/
private $pdfunite = '';
/**
* @var string DOWNLOAD_OUTPUT_FORMAT_RAW | DOWNLOAD_OUTPUT_FORMAT_JSON
*/
......@@ -83,6 +98,10 @@ class Download {
$this->db = new Database();
$this->html2pdf = new Html2Pdf($this->store->getStore(STORE_SYSTEM), $phpUnit);
$this->qpdf = $this->store->getVar(SYSTEM_CMD_QPDF, STORE_SYSTEM);
$this->gs = $this->store->getVar(SYSTEM_CMD_GS, STORE_SYSTEM);
$this->pdfunite = $this->store->getVar(SYSTEM_CMD_PDFUNITE, STORE_SYSTEM);
if (Support::findInSet(SYSTEM_SHOW_DEBUG_INFO_DOWNLOAD, $this->store->getVar(SYSTEM_SHOW_DEBUG_INFO, STORE_SYSTEM))) {
$this->downloadDebugLog = $this->store->getVar(SYSTEM_SQL_LOG, STORE_SYSTEM);
}
......@@ -140,7 +159,7 @@ class Download {
// $cmd = "pdftk $inputFiles cat output $concatFile 2>&1"; # Outdated. Hard to install on Ubuntu 18. Fails for recent PDFs.
// $cmd = "qpdf --empty --pages $inputFiles -- $concatFile 2>&1"; # Fails to merge identical files, if they contain references.
$cmd = "pdfunite $inputFiles $concatFile 2>&1"; // Based on poppler. URLs are preserved. Orientation and size are preserved.
$cmd = $this->pdfunite . " $inputFiles $concatFile 2>&1"; // Based on poppler. URLs are preserved. Orientation and size are preserved.
if ($this->downloadDebugLog != '') {
Logger::logMessage("Download: $cmd", $this->downloadDebugLog);
......@@ -188,7 +207,7 @@ class Download {
// Possible output: "Unimplemented Feature: Could not merge encrypted files ('ct.18.06.092-097.pdf')"
$line = implode(',', $rcOutput);
if (false !== ($line = strstr($line, "Unimplemented Feature: Could not merge encrypted files ("))) {
if (false !== ($line = strstr($line, "Feature not implemented: Could not merge encrypted files ("))) {
$arr = explode("'", $line, 3);
if (!empty($arr[1]) && file_exists($arr[1])) {
......@@ -201,13 +220,13 @@ class Download {
}
// Try 1: via 'qpdf --decrypt'
$cmdQpdf = "qpdf --decrypt '$backup' '$file' 2>&1"; // Try to decrypt file
$cmdQpdf = $this->qpdf . " --decrypt '$backup' '$file' 2>&1"; // Try to decrypt file
exec($cmdQpdf, $outputQpdf, $rcQpdf);
if ($rcQpdf != 0) {
// Try 2: via 'gs -sDEVICE=pdfwrite'
$cmdGs = "gs -sDEVICE=pdfwrite -dNOPAUSE -sOutputFile=\"$file\" -- \"$backup\"";
$cmdGs = $this->gs . " -sDEVICE=pdfwrite -dNOPAUSE -sOutputFile=\"$file\" -- \"$backup\"";
exec($cmdGs, $outputGs, $rcGs);
if ($rcGs != 0) {
......
......@@ -324,8 +324,6 @@ class Config {
F_BS_INPUT_COLUMNS => 'col-md-6 col-lg-6',
F_BS_NOTE_COLUMNS => 'col-md-3 col-lg-3',
SYSTEM_CMD_WKHTMLTOPDF => '/opt/wkhtmltox/bin/wkhtmltopdf',
F_CLASS => 'qfq-notify',
F_CLASS_PILL => 'qfq-color-grey-1',
......@@ -373,8 +371,13 @@ class Config {
SYSTEM_DOCUMENTATION_QFQ => SYSTEM_DOCUMENTATION_QFQ_URL,
SYSTEM_ENTER_AS_SUBMIT => 1,
SYSTEM_CMD_WKHTMLTOPDF => '/opt/wkhtmltox/bin/wkhtmltopdf',
SYSTEM_CMD_INKSCAPE => 'inkscape',
SYSTEM_CMD_CONVERT => 'convert',
SYSTEM_CMD_QPDF => 'qpdf',
SYSTEM_CMD_GS => 'gs',
SYSTEM_CMD_PDFUNITE => 'pdfunite',
SYSTEM_THUMBNAIL_DIR_SECURE => SYSTEM_THUMBNAIL_DIR_SECURE_DEFAULT,
SYSTEM_THUMBNAIL_DIR_PUBLIC => SYSTEM_THUMBNAIL_DIR_PUBLIC_DEFAULT,
......
......@@ -410,7 +410,9 @@ class StoreTest extends TestCase {
SYSTEM_SQL_LOG_MODE_AUTOCRON => 'error',
F_CLASS => 'qfq-notify',
SYSTEM_RENDER => SYSTEM_RENDER_SINGLE,
SYSTEM_CMD_QPDF => 'qpdf',
SYSTEM_CMD_GS => 'gs',
SYSTEM_CMD_PDFUNITE => 'pdfunite',
];
$body = <<< EOT
......
......@@ -28,6 +28,15 @@ cmdConvert = convert
# cat=config/config; type=string; label=Command 'wkhtmltopdf':Default is '/opt/wkhtmltox/bin/wkhtmltopdf'. Command to convert a HTML page to a PDF.
cmdWkhtmltopdf = /opt/wkhtmltox/bin/wkhtmltopdf
# cat=config/config; type=string; label=Command 'qpdf':Default is 'qpdf'. Will be used to convert PDF to PDF (try to repair) if merging of PDF fails.
cmdQpdf = qpdf
# cat=config/config; type=string; label=Command 'gs':Default is 'gs'. Will be used to decrypt and to convert PDF to PDF (try to repair) if merging of PDF fails.
cmdGs = gs
# cat=config/config; type=string; label=Command 'pdfunite':Default is 'pdfunite'. Will be used to merge PDFs.
cmdPdfunite = pdfunite
# cat=config/email; type=string; label=Options for SendEMail:Default is empty. General options. Check: http://caspian.dotconf.net/menu/Software/SendEmail. E.g.: 'sendEMail=-o tls=yes'
sendEMailOptions =
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment