Skip to content

client.render_to_file

client.render_to_file(path, **kwargs)

Render a PDF and stream the bytes straight to path. Built on render.pdf_stream, so memory usage stays bounded regardless of document size. Creates parent directories if missing. Overwrites existing files. On render error the partial file is removed before the error is re-raised.

Name Type Required Description
path String, Pathname (no description)
kwargs Object forwarded to `Resources::Render#pdf_stream`

nil

Code When
PoliPage::InvalidOptionsError See [errors](../../../production/errors/) for the full description.
PoliPage::ValidationError See [errors](../../../production/errors/) for the full description.
PoliPage::NotFoundError See [errors](../../../production/errors/) for the full description.
PoliPage::RateLimitError See [errors](../../../production/errors/) for the full description.
PoliPage::TimeoutError See [errors](../../../production/errors/) for the full description.
PoliPage::ConnectionError See [errors](../../../production/errors/) for the full description.
PoliPage::DownloadError See [errors](../../../production/errors/) for the full description.
PoliPage::InternalError See [errors](../../../production/errors/) for the full description.
PoliPage::APIError See [errors](../../../production/errors/) for the full description.
# frozen_string_literal: true
# Demonstrates: client.render_to_file — stream a rendered PDF straight to
# disk with bounded memory. Parent directories are created automatically;
# the partial file is removed on render error.
require "poli_page"
client = PoliPage::Client.new(api_key: ENV.fetch("POLI_PAGE_API_KEY"))
client.render_to_file(
"invoices/INV-001.pdf",
project: "billing",
template: "invoice",
data: { invoice_number: "INV-001", total: 1280 }
)
puts "wrote invoices/INV-001.pdf"