bitcrowd / chromic_pdf

Convenient HTML to PDF/A rendering library for Elixir based on Chrome & Ghostscript
Apache License 2.0
409 stars 37 forks source link

Add named session pools #273

Closed maltoe closed 1 year ago

maltoe commented 1 year ago

This adds support for multiple named session pools.

I figured that people in the past repeatedly wanted to have different values for our "global" options (e.g. disable_scripts) per print job, or rather likely per template. As this goes against my original idea of keeping "initialization work" strictly to the initialization (SpawnSession) and keep the amount of work per print job to a minimum, I'm inclined to point people to the existing possibility of launching multiple ChromicPDF instances with different configs (think: print queues). However, launching a separate ChromicPDF supervisor means launching additional OS processes of chromium, which seems wasteful. At this point I realized that we're lacking a middle layer in the session pool, i.e. differently configured sessions. This PR fixes that by introducing named session pools that can have pool-specific configs.

API

iex> ChromicPDF.start_link(session_pool: %{noscript: [disable_scripts: true], withscripts: []})
iex> ChromicPDF.print_to_pdf({:html, "test"}, session_pool: :noscript)

Docs

image

image