Output handling
The SDK gives you four ways to handle a rendered PDF: in-memory bytes, a stream of chunks, a write-to-disk helper, or a stored document on the server. Pick the one that matches how your code consumes the output.
In-memory (render.pdf)
Section titled “In-memory (render.pdf)”pdf = client.render.pdf( project: "billing", template: "invoice", data: { invoiceNumber: "INV-001" })# pdf is a binary-encoded String — write, upload, return as-is.Best for documents that fit comfortably in process memory.
Streaming (render.pdf_stream)
Section titled “Streaming (render.pdf_stream)”For large PDFs or piping straight to a file or object store, use pdf_stream and let the SDK keep memory bounded. Pass a block to consume chunks, or omit the block to get an Enumerator.
File.open("invoice.pdf", "wb") do |io| client.render.pdf_stream( project: "billing", template: "invoice", data: { invoiceNumber: "INV-001" } ) { |chunk| io.write(chunk) }endWrite to file (render_to_file)
Section titled “Write to file (render_to_file)”The client exposes a convenience helper that streams bytes to disk. Parent directories are created automatically. The PDF is written to a temporary file next to the target and renamed over it once complete: when the render, the download or the write fails, the target is left as it was. A file that cannot be written raises PoliPage::FileWriteError (io_error, message Failed to write PDF: <reason>).
client.render_to_file( "invoices/INV-001.pdf", project: "billing", template: "invoice", data: { invoiceNumber: "INV-001" })Server-side storage (render.document)
Section titled “Server-side storage (render.document)”When you want the PDF to live on Poli Page’s servers (for later download, preview, or thumbnails), use render.document. It returns a DocumentDescriptor with document_id, presigned_pdf_url, and a #download_pdf method.
doc = client.render.document( project: "billing", template: "invoice", data: { invoiceNumber: "INV-001" })pdf = doc.download_pdfpresigned_pdf_url has a ~15-minute TTL. If it expires, call client.documents.get(doc.document_id) to refresh.
Download timeout
Section titled “Download timeout”The client’s timeout: bounds the download of the PDF too. For download_pdf and render.pdf it bounds the whole download; for render.pdf_stream and render_to_file it bounds the wait for the first byte of the PDF and each wait for the next chunk, so a large PDF read at your own pace is never cut off. Past it, the call raises PoliPage::DownloadError with the message Failed to download PDF: timeout. The download is never retried.
Example
Section titled “Example”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: { invoiceNumber: "INV-001", total: 1280 })