diff --git a/.env.example.complete b/.env.example.complete index 37b46fec2..9d24fceeb 100644 --- a/.env.example.complete +++ b/.env.example.complete @@ -297,6 +297,11 @@ RECYCLE_BIN_LIFETIME=30 # Maximum file size, in megabytes, that can be uploaded to the system. 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 # Note, if set to 'true' the page editor may still escape scripts. ALLOW_CONTENT_SCRIPTS=false diff --git a/app/Config/dompdf.php b/app/Config/dompdf.php index a5490294c..55260a22a 100644 --- a/app/Config/dompdf.php +++ b/app/Config/dompdf.php @@ -8,6 +8,11 @@ * Do not edit this file unless you're happy to maintain any changes yourself. */ +$dompdfPaperSizeMap = [ + 'a4' => 'a4', + 'letter' => 'letter', +]; + return [ '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.) */ - 'default_paper_size' => 'a4', + 'default_paper_size' => $dompdfPaperSizeMap[env('EXPORT_PAGE_SIZE', 'a4')] ?? 'a4', /** * The default font family. diff --git a/app/Config/snappy.php b/app/Config/snappy.php index 0f012bef6..abdec8832 100644 --- a/app/Config/snappy.php +++ b/app/Config/snappy.php @@ -8,6 +8,11 @@ * Do not edit this file unless you're happy to maintain any changes yourself. */ +$snappyPaperSizeMap = [ + 'a4' => 'A4', + 'letter' => 'Letter', +]; + return [ 'pdf' => [ 'enabled' => true, @@ -15,6 +20,7 @@ return [ 'timeout' => false, 'options' => [ 'outline' => true, + 'page-size' => $snappyPaperSizeMap[env('EXPORT_PAGE_SIZE', 'a4')] ?? 'A4', ], 'env' => [], ], diff --git a/tests/Unit/ConfigTest.php b/tests/Unit/ConfigTest.php index 207fb7f59..8c5b43810 100644 --- a/tests/Unit/ConfigTest.php +++ b/tests/Unit/ConfigTest.php @@ -82,6 +82,20 @@ class ConfigTest extends TestCase $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 * then check the given config key to see if it matches the given result.