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

Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.

Ruby can render HTML directly to PDF and screenshots with a headless browser, but the documented HTML-to-Word route here does not create native DOCX in one step: it produces legacy .doc output that must be opened and saved in Microsoft Word. For browser-rendered output, Grover is the most direct starting point; use Ferrum when you need more control over browser capture.

Choose the route for each output

Output Ruby route Important distinction
PDF Grover or Ferrum Both use browser rendering for HTML; Prawn is a programmatic PDF layout library, not an HTML renderer.
Screenshot Grover or Ferrum Grover documents PNG and JPEG output; Ferrum documents browser screenshots including PNG, JPEG, and WebP.
DOCX metanorma/html2doc, then Microsoft Word The documented converter produces legacy .doc. Saving it as .docx is a separate Word step, not direct native-DOCX conversion.

The examples below use project-documented interfaces, but do not pin gem or browser versions: the project material does not establish a current compatibility matrix. Check the project README and verify the chosen Ruby, gem, Puppeteer/Chromium or browser installation together in the environment where the conversion will run.

Render HTML to PDF or images with Grover

Grover is the most direct single-library fit in the documented options when the input is a URL or an HTML string and the output is a PDF, PNG, or JPEG. It uses Puppeteer and Chromium. Follow the installation instructions in the Grover README for the Ruby gem and Puppeteer setup; the precise setup can depend on how your application deploys Chromium.

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

Convert a URL to PDF

After installing and configuring the gem as described by its README, the basic Ruby call is:

#1 Best Overall
require "grover"

pdf = Grover.new("https://example.com").to_pdf
File.binwrite("page.pdf", pdf)

This renders the page through a browser before returning PDF bytes. Replace the example URL with the page your application is authorized to capture. For dynamic pages, make sure the browser can reach the URL and that required content has finished loading before relying on the output.

Convert inline HTML to an image

Grover also accepts HTML input and documents PNG and JPEG output. For example:

require "grover"

html = <<~HTML
  <!doctype html>
  <html>
    <head><meta charset="utf-8"></head>
    <body><h1>Rendered from Ruby</h1><p>A small HTML example.</p></body>
  </html>
HTML

png = Grover.new(html).to_png
File.binwrite("page.png", png)

Use to_jpeg instead of to_png when JPEG output is what the consuming system needs. Confirm the method options in the Grover README for any output-specific settings; do not assume browser flags or options from another version behave identically.

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.

Use Ferrum for browser-level capture control

Ferrum drives a browser through the Chrome DevTools Protocol and exposes screenshot and PDF operations. Choose it when browser capture controls matter more than a compact conversion interface. Its documentation describes screenshot format, full-page capture, selector or area capture, quality and scale, as well as PDF paper formats and custom dimensions. Consult the Ferrum documentation for the exact options accepted by the version you install.

Capture a page screenshot

A basic capture pattern using Ferrum’s documented page screenshot interface is:

require "ferrum"

browser = Ferrum::Browser.new
begin
  page = browser.create_page
  page.go_to("https://example.com")
  page.screenshot(path: "page.png", full: true)
ensure
  browser.quit
end

The example requests a full-page screenshot. Ferrum documents output formats including PNG, JPEG and WebP, along with targeted selector or area capture and quality and scale controls. Apply those options using the names and value formats supported by your installed Ferrum release. Always close the browser, including when navigation or capture raises an error; a leaked browser process can exhaust memory or file descriptors in a long-running worker.

Write a PDF with Ferrum

Ferrum also documents page.pdf. A minimal pattern is:

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.
require "ferrum"

browser = Ferrum::Browser.new
begin
  page = browser.create_page
  page.go_to("https://example.com")
  pdf = page.pdf
  File.binwrite("page.pdf", pdf)
ensure
  browser.quit
end

Configure paper format or custom dimensions through the documented PDF options for the Ferrum version in use. A printed page can differ from a screenshot: PDF output is paginated, while a full-page screenshot is one image. Check page breaks, scaling, and margins with representative content rather than expecting identical layout.

Convert HTML to DOCX: account for the .doc intermediate

The documented Ruby project metanorma/html2doc converts HTML to the older Word .doc format. Its documented path to a .docx file requires opening that output in Microsoft Word and saving it as DOCX. It is therefore a two-stage workflow and should not be represented as a native HTML-to-DOCX renderer.

  1. Use the html2doc project according to its README to produce its legacy .doc output from the HTML.
  2. Open the resulting file in Microsoft Word, inspect the layout and content, and use Word’s Save As workflow to save a .docx copy.
  3. Reopen the saved DOCX and verify tables, images, fonts, page breaks, links, and other formatting that matters to your use case.

This route introduces both a format conversion and a Microsoft Word dependency. The available project documentation does not establish direct native-DOCX output, a formatting-fidelity guarantee, or an automated Word conversion workflow. If your pipeline must run unattended or cannot depend on Word, do not assume this route satisfies that requirement; evaluate a converter that explicitly supports HTML-to-DOCX and validate it against your documents.

The similarly named ruby-docx gem serves a different role. Its documentation describes interacting with existing DOCX documents, reading structures such as paragraphs and tables, and rendering paragraphs as HTML. That is not evidence that it converts arbitrary HTML into DOCX.

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

When Prawn is and is not the right tool

Prawn is for constructing PDFs with Ruby drawing and text APIs. Its README expressly says it is not an HTML-to-PDF generator and recommends Ferrum when HTML rendering is needed. Choose Prawn when you want to generate a document from programmatic layout primitives; choose Grover or Ferrum when the source is HTML whose browser layout should be rendered.

Operational checks before you automate conversion

  • Browser availability: Grover’s Puppeteer/Chromium path and Ferrum’s browser automation both require a working browser setup. A gem installing successfully does not by itself prove the browser executable is available in a production container.
  • Network access: URL-based rendering can fail or produce incomplete output if the browser cannot access the page or its assets. Test from the same network and runtime as the job.
  • Dynamic content: Content loaded asynchronously may not be present at the instant a capture occurs. Verify the resulting PDF or image and use documented waiting/configuration capabilities for the library and version selected.
  • Output validation: Check that the generated file exists, has nonzero size, opens in the intended viewer, and contains expected text or visual elements. For DOCX, inspect the Word-saved file separately.
  • Resource management: Browser processes are heavier than writing a file directly. Close browser instances in cleanup paths, and measure memory and processing time using representative pages before setting worker concurrency.
  • Version control: Pin tested gem dependencies and manage the browser/Puppeteer installation as part of deployment. The project references surfaced here do not establish current release versions or compatibility guarantees.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshooting common failures

The gem is installed, but Chromium cannot start

Check the Puppeteer/Chromium or browser installation and its executable availability in the actual runtime, not only on a developer workstation. Follow the selected library’s installation documentation, then retry a simple page capture before debugging application HTML.

The output is blank or missing page assets

Confirm that the page URL is reachable from the browser process and that external CSS, fonts, images, and scripts load there. For dynamic pages, determine whether content appears after navigation and configure the library’s documented wait behavior where available. Compare against a static local HTML sample to isolate network or page-script issues.

The screenshot cuts off content

Use Ferrum’s documented full-page option when the entire document is required, or capture a specific selector or area when only one region is needed. Check whether the relevant content is in a scrollable element rather than the document body; full-page behavior should be verified for the page structure in question.

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

The PDF pagination differs from the screenshot

This is expected when a continuous browser viewport is rendered into paper pages. Set the intended paper size or custom dimensions using the PDF options, then inspect page breaks and margins. Do not treat a screenshot’s dimensions as a substitute for PDF page setup.

The Word file is still .doc, not .docx

That matches the documented html2doc output. Open it in Microsoft Word and save a separate DOCX file; changing the filename extension alone does not convert the file format.

Or skip the browser setup

If the task is a screenshot of a live website rather than a local Ruby rendering pipeline, ScreenshotNeo offers a one-request screenshot API and an MCP server for AI agents. Its API can return PNG, JPEG, WebP, or PDF. Cookie and consent banners, newsletter popups, and chat widgets are removed before capture; those cleanup steps can be turned off. Bot checks/CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, with response headers identifying the page verdict and billing status. AI agents can use the MCP tools take_screenshot, get_page_info, and capture_pdf.

See the ScreenshotNeo API documentation. Example cURL request:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp

It includes 1,000 screenshots per month free with no card; paid plans start at $5 for 3,000 shots. Sign up for the free plan.

Frequently Asked Questions

Can one Ruby library create the PDF, screenshot, and DOCX outputs described here?

Grover directly documents PDF and PNG/JPEG output, but the documented DOCX route uses a separate legacy .doc-to-Word step.

Does ruby-docx convert arbitrary HTML into a Word document?

Its documented capabilities concern working with existing DOCX files; they do not establish arbitrary HTML-to-DOCX conversion.

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.

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