Configurable resource limits

View Source

Native Elixir PDF Utilities uses configurable limits to bound the memory, CPU, parsing work, and native raster allocation requested while processing PDF, HTML, CSS, image, SVG, and font data. These limits keep malformed or untrusted input from consuming resources without a predictable upper bound.

The library provides built-in values so every application starts with one consistent resource policy. Applications can override those values to match their request sizes, concurrency, memory budget, and timeout policy.

Configure limits under the library's OTP application in config/config.exs or config/runtime.exs:

config :native_elixir_pdf_utilities,
  limits: [
    max_svg_bytes: 10_000_000,
    max_svg_raster_dimension: 16_284
  ]

Omitted keys retain their built-in defaults. Configuration is validated when the library application starts. Unknown keys, repeated keys, non-positive values, excessively large integers, and inconsistent aggregate limits stop the application from starting. The startup error identifies the invalid setting.

Limits are process-wide and immutable for one application instance. Restart the application after changing them. Public PDF and rendering options cannot override these values.

Available limits

KeyDefaultScope
max_svg_bytes5,000,000Encoded SVG source
max_svg_raster_dimension8,192SVG raster width or height
max_svg_raster_pixels16,777,216SVG raster pixel count
max_image_count1,000Images in one render
max_image_source_bytes10,000,000One encoded image
max_aggregate_image_source_bytes50,000,000Encoded images in one render
max_decoded_image_bytes40,000,000One decoded image
max_aggregate_decoded_image_bytes80,000,000Decoded images in one render
max_background_image_tiles10,000Repeated background tiles in one render
max_layout_cardinality1,000Grid tracks, placements, and table spans
max_pdf_input_bytes50,000,000One PDF input
max_pdf_objects100,000Parsed PDF objects
max_pdf_object_stream_entries10,000Entries in one PDF object stream
max_pdf_pages10,000Pages in one PDF
max_pdf_page_tree_depth1,000PDF page-tree nesting
max_pdf_reference_chain_depth1,000Indirect-reference nesting
max_pdf_reference_resolution_work25,000Aggregate reference resolutions
max_pdf_value_depth100Nested PDF arrays and dictionaries
max_pdf_decoded_stream_bytes25,000,000One decoded PDF stream
max_pdf_decompression_ratio100Decoded-to-encoded stream ratio
max_pdf_xref_length_candidates1,000Candidate indirect /Length objects
max_pdf_xref_revisions1,000Incremental cross-reference revisions
max_pdf_info_value_bytes1,000,000One metadata value supplied for PDF generation or update
max_pdf_info_total_bytes5,000,000Metadata values supplied for one PDF generation or update
max_merge_inputs100PDFs in one merge
max_aggregate_merge_input_bytes100,000,000PDF bytes in one merge
max_merged_objects100,000Objects in merged output
max_merged_pages10,000Pages in merged output
max_split_outputs1,000PDFs returned by one split operation
max_split_object_writes1,000,000Aggregate objects serialized by one split operation
max_aggregate_split_output_bytes100,000,000Aggregate bytes returned by one split operation
max_text_decoded_content_bytes50,000,000Decoded content used by extraction
max_text_parsed_instructions100,000Unique parsed content instructions
max_text_stream_uses100,000Content stream references traversed
max_text_instruction_uses1,000,000Aggregate content instruction work
max_text_form_expansions10,000Form XObject executions
max_text_spans25,000Extracted spans per page
max_cmap_bytes1,000,000One CMap stream
max_cmap_entries100,000Mappings in one CMap
max_cid_width_entries65,536CID width entries
max_form_xobject_depth20Form XObject nesting
max_font_cache_entries64Parsed font files retained by the cache
max_system_font_cache_entries64Positive and negative installed-font discovery results retained by the cache

NativeElixirPdfUtilities.Limits.defaults/0 returns these built-in values, and NativeElixirPdfUtilities.Limits.effective/0 returns the values loaded for the current application instance.

Increasing a limit increases the maximum memory, CPU, parsing work, or native raster allocation an untrusted document can request. Consider the application's other resource controls when changing a value rather than tuning each limit in isolation.

PDF-format bounds, CSS validity ranges, and local-resource authorization are not resource tuning controls. Those checks remain fixed. In particular, local images and document-selected fonts still require a per-render base_url authorization root.