Guides · Ruby · Net::HTTP
Verify a fillable PDF render without opening the file in Ruby with Net::HTTP
When form-PDF generation is part of a pipeline — nightly exports, CI checks, a queue worker — "did it actually come out fillable?" needs a machine answer, not a human opening Acrobat. snapdok puts the verification data in the response headers, so your code can assert on the render it just received.
Below is a complete, runnable Ruby program using Net::HTTP, no third-party dependency needed. It reads your API key from the SNAPDOK_KEY environment variable — free keys take about thirty seconds and need no card.
require "json"
require "net/http"
require "uri"
uri = URI("https://snapdok.io/v1/render")
res = Net::HTTP.start(uri.host, uri.port, use_ssl: true, read_timeout: 90) do |http|
req = Net::HTTP::Post.new(uri)
req["Authorization"] = "Bearer #{ENV.fetch("SNAPDOK_KEY")}"
req["Content-Type"] = "application/json"
req.body = JSON.generate({
url: "https://your-app.com/intake-form",
format: "pdf",
pdf_forms: true,
pdf_form_only: true,
})
http.request(req)
end
raise "snapdok error #{res.code}: #{res.body}" unless res.is_a?(Net::HTTPSuccess)
File.binwrite("checked.pdf", res.body)
puts "#{res["X-Form-Fields"]} # assert on this in CI"
Three headers carry the contract. X-Form-Fields is the number of AcroForm fields placed — assert it equals the number of controls your form has, and you have a regression test that catches a broken deploy of your own form page, too. X-Form-Skipped counts controls that could not convert (file pickers, hidden inputs, iframe forms); a sudden rise means someone changed the form. X-Form-Extracted tells you whether pdf_form_only actually pruned the page or fell back to the full page — fallback is legitimate output, but your layout expectations may differ.
Two operational notes for pipelines: failed renders are never metered, and a repeat of an identical request inside 24 hours returns X-Cache: HIT and is also not charged — so a retrying job that occasionally double-fires does not eat quota. Rate limits surface as HTTP 429 with a Retry-After header; honour it instead of hammering.
Notes for Net::HTTP
Stdlib only — no gems. The traps Net::HTTP is famous for, all handled in the sample: TLS is not automatic (set use_ssl: true or you will POST in the clear to port 80 and get a redirect); the default read_timeout of 60 s is close enough to real render times that raising it is wise; and the response body is a binary-ready String, but write it with File.binwrite — plain File.write on Windows would mangle line-ending bytes in the PDF. Check is_a?(Net::HTTPSuccess): Net::HTTP never raises on HTTP error statuses.
Response headers worth reading
| Header | Meaning |
|---|---|
X-Form-Fields | Fields placed — the number to assert on. |
X-Form-Skipped | Unconvertible controls; watch for regressions. |
X-Form-Extracted | Prune result when pdf_form_only was requested. |
Retry-After | Present on 429 — seconds to back off. |
Full parameter reference: the docs. Hard numbers on caps and timeouts: limits.
Related guides
Same task, other stacks
- Verify a fillable PDF render without opening the file in Python with requests
- Verify a fillable PDF render without opening the file in Node.js with built-in fetch
- Verify a fillable PDF render without opening the file in PHP with cURL extension
More with Ruby + Net::HTTP
- Convert an HTML form to a fillable PDF
- Get a fillable PDF of just the form — no nav, no footer
- Generate a fillable invoice PDF from a web page
- Turn an online registration form into a fillable PDF
- Wait for a JavaScript-rendered form, then make it fillable
- Convert a URL to PDF
- Take a full-page screenshot
- Capture very tall pages as numbered tiles
- Take a retina-quality (2x) screenshot
- Take a JPEG screenshot at a custom viewport size
- Use the 24-hour render cache to cut costs
- Take a screenshot of a URL
- Capture a JavaScript-heavy page after it settles
- Wait for a specific element before capturing
- Add page numbers and headers to a PDF