From 0329e0273074082b7153d6eb6a5866ff2d3d8a8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9mence=20Lesn=C3=A9?= Date: Sat, 15 Jun 2024 16:32:00 +0200 Subject: [PATCH] finops: Compress PDF --- function_app.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/function_app.py b/function_app.py index d3aa67a..b550dc1 100644 --- a/function_app.py +++ b/function_app.py @@ -52,6 +52,7 @@ # Clients _container_client: Optional[ContainerClient] = None +pikepdf.settings.set_flate_compression_level(9) # Maximum compression level for PDFs # Custom types T = TypeVar("T") @@ -104,6 +105,8 @@ async def _upload(data: memoryview, in_path: str) -> None: filename_or_stream=out_stream, linearize=True, # Allows compliant readers to begin displaying a PDF file before it is fully downloaded min_version=CONFIG.features.sanitize_pdf_version, # Note, if a second PDF is created with a higher version, hash will be different and cache won't work + object_stream_mode=pikepdf.ObjectStreamMode.generate, # Generate object streams + recompress_flate=True, # Recompress with flate compression ) await _upload( data=out_stream.getbuffer(),