---
title: "Print on Demand"
description: "Print on Demand presents a resource-conscious alternative to scaling an application by separating PDF generation from the main server. The post explains how a Fly.io PDF appliance uses Fly-Replay to route a PDF request to a machine running headless Chrome, which requests the original page without its “.pdf” extension and converts the returned HTML into a PDF. Each machine reuses one Chrome instance across requests, while auto_stop_machines allows idle machines to stop and restart on demand. Integration requires cloning the GitHub repository, creating and configuring an app, deploying it, and returning a fly-replay response header for PDF-directed requests. The extracted production code is packaged for deployment with existing applications, supports session, cookies, and basic authentication through passed-back HTTP headers, and can serve applications using different languages and frameworks."
---

# Print on Demand

[Fly.io](https://yomu.fyi/company/fly-io) · Nov 29, 2023

**Type:** Problem & solution

## Summary

Print on Demand presents a resource-conscious alternative to scaling an application by separating PDF generation from the main server. The post explains how a Fly.io PDF appliance uses Fly-Replay to route a PDF request to a machine running headless Chrome, which requests the original page without its “.pdf” extension and converts the returned HTML into a PDF. Each machine reuses one Chrome instance across requests, while auto\_stop\_machines allows idle machines to stop and restart on demand. Integration requires cloning the GitHub repository, creating and configuring an app, deploying it, and returning a fly-replay response header for PDF-directed requests. The extracted production code is packaged for deployment with existing applications, supports session, cookies, and basic authentication through passed-back HTTP headers, and can serve applications using different languages and frameworks.

## Context

PDF generation can consume more memory than a typical web server and is used less often than the rest of an application. Separating it into its own application makes resource usage more predictable, allows independent scaling, and keeps the main application image smaller and faster to start.

## Approach / What changed

The PDF appliance receives requests replayed from an existing application, runs a reused Chrome instance to fetch the corresponding HTML page, converts that HTML to a PDF, and returns the result. Fly Machines can stop when idle and restart when needed through the auto\_stop\_machines setting. Applications integrate by returning a fly-replay response header for PDF routes or requests.

## Takeaways

- A single Chrome instance is reused across requests on each machine, avoiding the cost of starting a new browser for every PDF.
- HTTP headers are passed back to the application, allowing existing sessions, cookies, and basic authentication to work with the appliance.
- The appliance is written in JavaScript, runs on Bun, was designed for a Ruby on Rails application, and can be used with applications built in other languages and frameworks.

**Tags:** [Architecture](https://yomu.fyi/topic/architecture), [Bun](https://yomu.fyi/topic/bun), [Fly Machines](https://yomu.fyi/topic/fly-machines), [JavaScript](https://yomu.fyi/topic/javascript)

- Source: [Fly.io](https://fly.io/blog/print-on-demand)
- Source URL: https://fly.io/blog/print-on-demand
- Ingested by Yomu: 2026-09-02T11:57:40.195Z

[Read original post](https://fly.io/blog/print-on-demand)
