Added option to configure PDF export paper size

For #995
This commit is contained in:
Dan Brown 2022-01-30 17:40:42 +00:00
parent e17cdab420
commit a709fd04b5
No known key found for this signature in database
GPG Key ID: 46D9F943C24A2EF9
4 changed files with 31 additions and 1 deletions

View File

@ -297,6 +297,11 @@ RECYCLE_BIN_LIFETIME=30
# Maximum file size, in megabytes, that can be uploaded to the system. # Maximum file size, in megabytes, that can be uploaded to the system.
FILE_UPLOAD_SIZE_LIMIT=50 FILE_UPLOAD_SIZE_LIMIT=50
# Export Page Size
# Primarily used to determine page size of PDF exports.
# Can be 'a4' or 'letter'.
EXPORT_PAGE_SIZE=a4
# Allow <script> tags in page content # Allow <script> tags in page content
# Note, if set to 'true' the page editor may still escape scripts. # Note, if set to 'true' the page editor may still escape scripts.
ALLOW_CONTENT_SCRIPTS=false ALLOW_CONTENT_SCRIPTS=false

View File

@ -8,6 +8,11 @@
* Do not edit this file unless you're happy to maintain any changes yourself. * Do not edit this file unless you're happy to maintain any changes yourself.
*/ */
$dompdfPaperSizeMap = [
'a4' => 'a4',
'letter' => 'letter',
];
return [ return [
'show_warnings' => false, // Throw an Exception on warnings from dompdf 'show_warnings' => false, // Throw an Exception on warnings from dompdf
@ -150,7 +155,7 @@ return [
* *
* @see CPDF_Adapter::PAPER_SIZES for valid sizes ('letter', 'legal', 'A4', etc.) * @see CPDF_Adapter::PAPER_SIZES for valid sizes ('letter', 'legal', 'A4', etc.)
*/ */
'default_paper_size' => 'a4', 'default_paper_size' => $dompdfPaperSizeMap[env('EXPORT_PAGE_SIZE', 'a4')] ?? 'a4',
/** /**
* The default font family. * The default font family.

View File

@ -8,6 +8,11 @@
* Do not edit this file unless you're happy to maintain any changes yourself. * Do not edit this file unless you're happy to maintain any changes yourself.
*/ */
$snappyPaperSizeMap = [
'a4' => 'A4',
'letter' => 'Letter',
];
return [ return [
'pdf' => [ 'pdf' => [
'enabled' => true, 'enabled' => true,
@ -15,6 +20,7 @@ return [
'timeout' => false, 'timeout' => false,
'options' => [ 'options' => [
'outline' => true, 'outline' => true,
'page-size' => $snappyPaperSizeMap[env('EXPORT_PAGE_SIZE', 'a4')] ?? 'A4',
], ],
'env' => [], 'env' => [],
], ],

View File

@ -82,6 +82,20 @@ class ConfigTest extends TestCase
$this->checkEnvConfigResult('ALLOW_UNTRUSTED_SERVER_FETCHING', 'true', 'dompdf.defines.enable_remote', true); $this->checkEnvConfigResult('ALLOW_UNTRUSTED_SERVER_FETCHING', 'true', 'dompdf.defines.enable_remote', true);
} }
public function test_dompdf_paper_size_options_are_limited()
{
$this->checkEnvConfigResult('EXPORT_PAGE_SIZE', 'cat', 'dompdf.defines.default_paper_size', 'a4');
$this->checkEnvConfigResult('EXPORT_PAGE_SIZE', 'letter', 'dompdf.defines.default_paper_size', 'letter');
$this->checkEnvConfigResult('EXPORT_PAGE_SIZE', 'a4', 'dompdf.defines.default_paper_size', 'a4');
}
public function test_snappy_paper_size_options_are_limited()
{
$this->checkEnvConfigResult('EXPORT_PAGE_SIZE', 'cat', 'snappy.pdf.options.page-size', 'A4');
$this->checkEnvConfigResult('EXPORT_PAGE_SIZE', 'letter', 'snappy.pdf.options.page-size', 'Letter');
$this->checkEnvConfigResult('EXPORT_PAGE_SIZE', 'a4', 'snappy.pdf.options.page-size', 'A4');
}
/** /**
* Set an environment variable of the given name and value * Set an environment variable of the given name and value
* then check the given config key to see if it matches the given result. * then check the given config key to see if it matches the given result.