Skip to content

Commit

Permalink
finops: Compress PDF
Browse files Browse the repository at this point in the history
  • Loading branch information
clemlesne committed Jun 15, 2024
1 parent c81eda7 commit 0329e02
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions function_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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(),
Expand Down

0 comments on commit 0329e02

Please sign in to comment.