Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
HTML to PDF

How to Generate Full-Height PDFs in Ruby with an API

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To create a single-page PDF whose height follows the rendered HTML, send the page to an API that supports content-based sizing. In Ruby, PDFShift documents format: "1280xauto"; the service calculates the required height. Pdfcrowd offers the equivalent setPageHeight("-1"). Browserless requires its function endpoint, where your code measures the page and supplies the height; its ordinary PDF endpoint remains paginated.

What “full-height PDF” means

A full-height PDF is one PDF page with a fixed width and a height derived from the rendered content. It is not a conventional multi-page document with page-break rules removed. The browser or conversion engine must finish layout, determine the document’s height, and then create one page large enough to contain it.

This format works well for long webpages, invoices, dashboards and archival snapshots that should scroll as one canvas. It is less suitable for printing, screen readers and viewers that impose page-size limits. Keep a paginated version when readers need standard Letter or A4 sheets.

Fastest Ruby implementation: PDFShift

PDFShift’s Ruby example posts JSON to https://api.pdfshift.io/v3/convert/pdf and uses format: "1280xauto". The width is 1,280 pixels; auto asks the service to calculate height from the rendered page.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall

Prerequisites

  • Ruby with the standard net/http, uri and json libraries.
  • A PDFShift API key stored outside source control, for example in PDFSHIFT_API_KEY.
  • A publicly reachable URL, or HTML supplied through the provider’s documented input fields.

Complete Ruby script

require "net/http"
require "uri"
require "json"

api_uri = URI("https://api.pdfshift.io/v3/convert/pdf")
api_key = ENV.fetch("PDFSHIFT_API_KEY")

payload = {
  source: "https://example.com/report",
  format: "1280xauto"
}

request = Net::HTTP::Post.new(api_uri)
request["Content-Type"] = "application/json"
request["Authorization"] = "Basic #{Base64.strict_encode64("#{api_key}:")}"
request.body = JSON.generate(payload)

http = Net::HTTP.new(api_uri.host, api_uri.port)
http.use_ssl = true
http.open_timeout = 15
http.read_timeout = 90

response = http.request(request)
unless response.is_a?(Net::HTTPSuccess)
  warn "PDF conversion failed (#{response.code}): #{response.body}"
  exit 1
end

File.binwrite("output.pdf", response.body)
puts "Wrote output.pdf (#{response.body.bytesize} bytes)"

Add require "base64" near the top when using the Basic-auth form shown above. Follow your PDFShift account documentation if its current authentication header differs; authentication details and API behavior can change.

Why binary writing matters

PDF is binary data. Use File.binwrite or open the file with "wb". Converting the response to UTF-8, printing it to a terminal, or parsing it as JSON corrupts the document.

Supplying HTML instead of a URL

Replace source with the HTML input field documented for your PDFShift account when the page is generated dynamically. Ensure stylesheets, fonts and images are reachable by the rendering service, or embed them as data URLs. A private localhost address will not be reachable from a hosted API.

Other API strategies

Pdfcrowd: an explicit unbounded height

Pdfcrowd documents setPageHeight("-1") for a single page that expands vertically to fit all content. This is useful when you want the page-height decision to be explicit in a Ruby client rather than encoded in a format string. Pdfcrowd cautions that 200 inches is a safe maximum for other custom heights because some viewers may fail with larger pages. The -1 mode is therefore preferable to guessing a very large number, but test the resulting file in the viewers your users rely on.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Browserless: measure first, then create the PDF

Browserless states that its /pdf REST endpoint does not create one continuous long page. Use its /function API instead: run browser code that waits for the page, measures the rendered document, and passes an appropriate height to PDF generation. This gives you control over lazy loading and client-side layout, but you own the measurement logic and its edge cases.

HTML2PDFAPI and DocRaptor

HTML2PDFAPI documents Ruby Net::HTTP and Rails/HTTParty requests, URL or HTML input, page format, landscape mode and print backgrounds, but the cited documentation does not describe a dedicated automatic-height flag. DocRaptor’s Ruby client accepts document content or a URL; the cited client page likewise does not document a full-height setting. Confirm current options before selecting either for a single-page requirement.

Local Ruby options

PDFKit and wkhtmltopdf

PDFKit wraps the wkhtmltopdf executable and can return bytes or write a file. It exposes page-size options, but the cited repository does not establish an automatic single-page content-height mode. You would need to calculate a height yourself and verify WebKit’s CSS and JavaScript behavior against your page.

Playwright for Ruby

Chromium’s page.pdf supports width, height, margins, paper formats, page ranges and output paths. The API reference does not promise automatic content-height sizing, so measure the rendered page and pass a suitable height. Account for fonts, images, animations and lazy content before measuring.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Prawn

Prawn creates PDFs with Ruby-native layout APIs through Prawn::Document or Prawn::Document.generate. It is a strong choice when you are composing text and graphics yourself, not when you need browser-accurate HTML and CSS. You control the page geometry directly, so a full-height page can be designed from your data model.

Choosing an approach

Approach Height behavior Rendering source Best fit
PDFShift 1280xauto calculates content height Hosted HTML or URL conversion Direct Ruby integration with minimal measurement code
Pdfcrowd setPageHeight("-1") Hosted conversion Explicit single-page setting in the client
Browserless /function Your code measures and supplies height Browser-rendered page Custom JavaScript, authentication or lazy-loading control
Playwright Ruby Caller-calculated height Local Chromium Infrastructure control and browser automation
Prawn Programmatic geometry Ruby drawing commands Documents built without HTML rendering

Compare not only the height flag but also CSS and JavaScript fidelity, access to authenticated pages, execution ownership, timeouts, maximum page dimensions and viewer compatibility.

Making the result reliable

Wait for the real layout

Do not measure or capture immediately after navigation when the page loads fonts, images or JavaScript data asynchronously. Wait for a meaningful selector, network idle, a known delay or an application-ready signal. For lazy images, trigger the loading behavior before height calculation.

Control print styling

Print CSS can hide navigation, change colors or insert page breaks. Decide whether the PDF should use print media or screen media, then test @media print, background colors, fixed headers and positioned elements at the target width.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Keep secrets and responses safe

  • Read API keys from environment variables or a secret manager.
  • Use HTTPS and never log authorization headers or private HTML.
  • Check status codes before writing a file; an error page can otherwise be saved as output.pdf.
  • Set connection and read timeouts, and retry only transient failures with bounded backoff.
  • Validate the output begins with a PDF signature and has a nonzero size before publishing it.

Plan for very tall pages

One enormous page can exceed viewer, printer or renderer limits. Pdfcrowd identifies 200 inches as a safe maximum for other custom heights, not a guarantee that every viewer accepts taller pages. If your content may exceed practical limits, switch to standard pages or split the document intentionally.

Ruby, cURL, Python and Node.js request patterns

The following minimal clients show the same hosted-conversion shape. Adapt authentication and payload names to the provider you choose.

cURL

curl -X POST "https://api.pdfshift.io/v3/convert/pdf" 
  -H "Authorization: Basic $PDFSHIFT_AUTH" 
  -H "Content-Type: application/json" 
  --data '{"source":"https://example.com/report","format":"1280xauto"}' 
  -o output.pdf

Python

import os
import requests

payload = {"source": "https://example.com/report", "format": "1280xauto"}
r = requests.post(
    "https://api.pdfshift.io/v3/convert/pdf",
    json=payload,
    auth=(os.environ["PDFSHIFT_API_KEY"], ""),
    timeout=90,
)
r.raise_for_status()
with open("output.pdf", "wb") as f:
    f.write(r.content)

Node.js

const res = await fetch("https://api.pdfshift.io/v3/convert/pdf", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "Authorization": `Basic ${process.env.PDFSHIFT_AUTH}`
  },
  body: JSON.stringify({
    source: "https://example.com/report",
    format: "1280xauto"
  })
});
if (!res.ok) throw new Error(`${res.status}: ${await res.text()}`);
const bytes = Buffer.from(await res.arrayBuffer());
await require("fs").promises.writeFile("output.pdf", bytes);

Troubleshooting

The file opens as an error message

Inspect the HTTP status and response content before saving. Authentication failures, invalid JSON and unreachable URLs commonly return HTML or JSON rather than PDF bytes.

The PDF is still paginated

Check that the provider’s single-page option is actually enabled. PDFShift requires 1280xauto; Pdfcrowd requires setPageHeight("-1"); Browserless requires a measured height through /function, not ordinary /pdf.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Content is cut off at the bottom

The capture likely occurred before fonts, images or client-side data finished loading, or the measured height was taken before lazy content expanded. Wait for a readiness selector and recalculate after all assets load.

Styles or images are missing

Verify that every resource is reachable from the renderer, HTTPS certificates are valid, relative URLs resolve against the intended page, and authentication headers or cookies are supplied where required.

A viewer refuses the document

Reduce the page height, use the documented 200-inch safety guidance for custom Pdfcrowd heights, or generate a paginated PDF. Viewer support is not uniform for extreme page dimensions.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

ScreenshotNeo provides a hosted capture API and MCP server for developers. Its cleanup step accepts cookie/consent banners and removes more than 60 known consent platforms, newsletter popups and chat widgets before capture; each step can be disabled. Bot checks, CAPTCHAs, blank pages, timeouts, failed loads and cache hits are not billed, and response headers identify the page verdict and billing result.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For a one-call capture, use the documented endpoint (adapt the target URL):

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

Ruby, Python and Node.js examples and the PDF capture options are in the ScreenshotNeo documentation. It also offers an MCP server with take_screenshot, get_page_info and capture_pdf tools for Claude, Cursor and other MCP clients. Every plan includes all features; 1,000 shots per month are free without a card, and paid plans start at $5 for 3,000 shots. Create a free ScreenshotNeo account.

Frequently Asked Questions

Is a full-height PDF the same as a full-page screenshot?

No. A PDF is a document with page geometry and selectable content; a screenshot is an image. Browser rendering, fonts and viewer limits affect each differently.

Should I use one long page for a document intended to be printed?

Usually not. Standard Letter or A4 pages are more predictable for printing, accessibility and sharing; reserve a continuous page for scroll-oriented records.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Can I guarantee that every PDF viewer will open an extremely tall page?

No. Viewer limits vary. Test representative files and fall back to pagination when height becomes impractical.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Read next

Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.