Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Repair Windows errors before they cause bigger problemsFix Now →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Choose the PDF method based on how the page authenticates: pass a valid session cookie for a cookie-protected page, provide credentials to a renderer that supports HTTP Basic Authentication, or build the PDF from application data instead of rendering a webpage. In Rails, generate the bytes only after authorizing the requesting user, then return them with send_data. These approaches solve different problems: access to the source page is not the same as encrypting the PDF you create.
Identify the page’s authentication before choosing a renderer
A password prompt does not necessarily mean HTTP Basic Authentication. A site may show a login form, establish a server-side session, and then identify the browser with a cookie. Another site may use HTTP Basic Authentication, which prompts the browser for a username and password at the HTTP layer. The renderer must receive the kind of credential the site actually expects.
- Cookie or session login: authenticate through an authorized login flow and give the renderer the resulting session cookie, or use an already authenticated browser context if the renderer supports it.
- HTTP Basic Authentication: supply the username and password through a renderer’s Basic Auth option.
- Application data: if you control the content and need a designed report rather than a copy of an existing page, generate the document directly with a PDF library.
Before automating retrieval, confirm that you are authorized to use the account and that the target site permits the access. Do not try to evade a login, CAPTCHA, or other access control.
Choose a Ruby PDF approach
| Approach | Authentication fit | JavaScript and rendering | Deployment dependency | Best suited to |
|---|---|---|---|---|
| PDFKit | Can pass cookies for a session-authenticated page | Uses an HTML-to-PDF renderer; confirm its behavior against the page’s scripts and assets | Its underlying renderer must be available in the deployment environment | Rendering an accessible URL or HTML with the required cookie |
| Wicked PDF | Can be used when the rendered HTML can be given the required access | Uses wkhtmltopdf; test the target page’s scripts, assets, fonts, redirects, and TLS | The wkhtmltopdf executable must be installed as well as the gem | Rails applications already using the wkhtmltopdf workflow |
| FerrumPdf | Documents an explicit authorization option for HTTP Basic Authentication | Browser-capable rendering is useful when the page depends on browser behavior | Verify compatible browser and operating-system requirements for your deployment | Basic-authenticated URLs or pages needing browser rendering |
| Prawn | Does not log in to or fetch a protected page | Composes a PDF from Ruby code and data rather than rendering a webpage | Ruby library; no webpage renderer is implied | Reports, invoices, and other PDFs your application constructs |
PDFKit and Wicked PDF are HTML-to-PDF paths, not authentication systems. Wicked PDF delegates conversion to the wkhtmltopdf shell utility, so installing the gem alone is insufficient. FerrumPdf’s documented authorize option is specifically useful for Basic Auth; it should not be mistaken for a way to submit an arbitrary website login form. Prawn can encrypt a PDF it creates, but encryption does not provide access to a protected source page.
#1 Best Overall
Render a session-protected page with PDFKit
For a page that uses a session cookie, obtain that cookie through an authorized login flow, then pass it to PDFKit. This example assumes the application has already obtained session_cookie securely; it does not implement login or expose a password.
require "pdfkit"
url = "https://example.test/account"
session_cookie = ENV.fetch("PAGE_SESSION_COOKIE")
kit = PDFKit.new(
url,
cookie: { "session_id" => session_cookie }
)
pdf_bytes = kit.to_pdf
File.binwrite("account.pdf", pdf_bytes)
Replace session_id with the actual cookie name issued by the site. A cookie’s name, value, domain, and lifetime are determined by that site; a cookie from a different environment or an expired session will not grant access. Keep session values out of source control, exception messages, request logs, and diagnostic output. The PDFKit project documents the cookie option for this handoff.
If you use PDFKit in Rails, keep rendering separate from authorization: first establish that the current user may access the requested account or record, then render the corresponding permitted URL, and return the bytes. Do not let a caller supply an arbitrary URL to a server-side renderer without validating it; unrestricted URL fetching can expose internal network resources.
Rank #2
Render an HTTP Basic Auth page with FerrumPdf
When the origin uses HTTP Basic Authentication, FerrumPdf documents an authorize option that takes a user and password. Keep the credentials in environment-backed configuration rather than committing them.
require "ferrum_pdf"
pdf_bytes = FerrumPdf.render_pdf(
url: "https://example.test/private",
authorize: {
user: ENV.fetch("PAGE_USER"),
password: ENV.fetch("PAGE_PASSWORD")
}
)
File.binwrite("private.pdf", pdf_bytes)
Use this option only when the page is actually protected by HTTP Basic Authentication. A normal HTML login form usually expects a browser to submit form fields, receive a session cookie, and follow redirects; Basic Auth credentials will not complete that flow. For JavaScript-heavy pages, a browser-capable renderer may be necessary, but confirm the renderer’s handling of the specific page and deployment environment rather than assuming every browser feature or asset will work.
Return a generated PDF from Rails
In a controller, authorize the request and finish rendering before sending the resulting bytes. The following illustrates the response step for a page whose session cookie has already been obtained securely:
Rank #3
class ReportsController < ApplicationController
def show
report = current_user.reports.find(params[:id])
authorize report
session_cookie = obtain_authorized_page_cookie(report)
kit = PDFKit.new(
report.source_url,
cookie: { "session_id" => session_cookie }
)
pdf_bytes = kit.to_pdf
send_data pdf_bytes,
filename: "report-#{report.id}.pdf",
type: "application/pdf",
disposition: "attachment"
end
end
authorize and obtain_authorized_page_cookie represent application-specific authorization and credential handling; they are not built-in Rails methods. Implement them using your authorization system and approved login flow. Restrict or validate report.source_url so an attacker cannot make the server render an arbitrary destination. For large or slow renders, consider a background job and a controlled download flow instead of holding an interactive request open.
Build and encrypt a PDF with Prawn
Use Prawn when the content comes from your application and you want to lay out a document yourself. It does not visit the webpage or authenticate to it. Its encryption options protect the output PDF, which is a separate concern from source-page access.
Recommended Free Tools
require "prawn"
pdf = Prawn::Document.new
pdf.text "Report"
pdf.encrypt_document(
user_password: ENV.fetch("PDF_USER_PASSWORD"),
owner_password: ENV.fetch("PDF_OWNER_PASSWORD")
)
pdf_bytes = pdf.render
File.binwrite("report.pdf", pdf_bytes)
Set both passwords through protected configuration and test the resulting document with the PDF viewers your recipients use. Do not describe an encrypted report as having authenticated the source page: Prawn creates and protects the document from Ruby data.
Rank #4
Or skip the browser setup
If the URL is reachable by ScreenshotNeo under the credentials and access conditions you provide, its screenshot API can return a PDF as well as an image. It is an alternative capture service, not a replacement for authorizing access to a private account or completing an unsupported login flow. Its options include custom headers, cookies, and Authorization, but use only credentials you are permitted to provide and check the API documentation for the exact request parameters.
For a public page, this cURL example requests a capture:
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
See the ScreenshotNeo API documentation for output-format and authentication parameters; adapt the target URL and request the PDF format as documented when you need a PDF rather than the example image. Cookie banners, newsletter popups, and chat widgets are removed before capture by default, with each step configurable. Bot checks, blank pages, failed loads, and cache hits are not billed, and responses identify page verdict and billing status. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents. The Free plan includes 1,000 shots per month without a card; paid plans start at $5 for 3,000 shots. Details are at ScreenshotNeo. Sign up for 1,000 free screenshots a month with no card.
Troubleshoot common failures
- The PDF shows a login page: the renderer did not receive a valid session cookie, or the target uses a form-based login rather than Basic Auth. Confirm the authentication type, cookie name and current validity, and redirects after login.
- Basic Auth returns an authorization error: verify that the origin uses HTTP Basic Authentication and that the configured user and password are correct. A website login form requires a different flow.
- The output is blank or missing page content: check whether the page needs JavaScript, waits for asynchronous data, or depends on assets the renderer cannot load. Try a browser-capable renderer and verify the target’s expected load behavior.
- Fonts, images, or styles are missing: check asset URLs, access restrictions, TLS, redirects, and whether the renderer can reach those resources from the deployment host.
- Wicked PDF works locally but not after deployment: confirm that the
wkhtmltopdfexecutable is installed and executable in the deployed environment, not merely that the gem is present. - Rendering fails after a system or dependency update: pin and test compatible gem, binary, browser, and operating-system versions. A complete compatibility matrix is not established here, so validate the actual production combination.
- Rails requests time out: a slow page or lengthy render may exceed the web request budget. Measure the render in your environment and move long jobs to background processing where appropriate.
Reliability, security, and cost considerations
Rendering is a network operation as well as a document operation. A result depends on the source page, credentials, redirects, JavaScript, fonts, assets, renderer, and server environment. Test representative pages in the deployment environment, including expired sessions and unavailable assets, and handle failures without returning a partial or misleading PDF.
Best Value
Protect credentials and cookies as secrets: use controlled configuration, limit access, avoid logging them, and do not include them in generated filenames or user-visible errors. Authorize the requesting user independently of the page’s own login. If the page contains sensitive data, apply the application’s access controls to both generation and delivery, and consider whether the generated file needs a defined retention period.
No authoritative performance or adoption figures are established for these Ruby approaches here, so benchmark your own pages and infrastructure. Compare recurring operational needs as well as code: PDFKit/Wicked PDF require an HTML rendering dependency, FerrumPdf requires a compatible browser setup, while Prawn requires you to implement document layout. Costs depend on your hosting, rendering workload, and any external service plan; there is no universal per-document cost established for the Ruby libraries.
Frequently Asked Questions
Can I use a website password in a PDFKit cookie option?
No. The cookie option expects a cookie name and value obtained from an authenticated session, not the account password.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Does Prawn convert an existing webpage to PDF?
No. Prawn composes PDFs from Ruby code and data; it does not fetch or render a webpage.
Does PDF encryption protect the original webpage?
No. Encryption applies to the PDF output, not access to the source page.
Quick Recap
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.

