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 DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
World desk4 min

How to Create a PDF of a Web Page with PhantomJS

A practical PhantomJS PDF walkthrough with runnable JavaScript, a rasterize.js command, viewport guidance, and troubleshooting for failed or delayed page loads.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To create a PDF with PhantomJS, open the page with a webpage object, check that navigation succeeded, render to a filename ending in .pdf, then exit PhantomJS. PhantomJS supports PDF output through page.render, but its development is suspended, so treat it as a legacy option rather than a good default for a new system.

Use a PhantomJS script to render a web page as PDF

Save this as webpage-to-pdf.js. Replace the example URL and output filename as needed.

As an Amazon Associate I earn from qualifying purchases.

var page = require('webpage').create();
var url = 'https://example.com/';
var output = 'page.pdf';

page.open(url, function (status) {
  if (status !== 'success') {
    console.log('Unable to load the address!');
    phantom.exit(1);
    return;
  }

  page.render(output);
  phantom.exit();
});

Run it from the directory containing the script:

phantomjs webpage-to-pdf.js

page.open(url, callback) invokes the callback with success or fail after loading finishes. The script checks that result and exits with an error instead of attempting to render a failed navigation. The official API documentation describes the callback behavior at page.open.

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

Run the official rasterize.js example

PhantomJS’s screen-capture guide also documents a command-line example using rasterize.js:

#1 Best Overall
Philips 24 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 241V8LB
  • CRISP CLARITY: This 23.8″ Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
  • INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
  • THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors
  • WORK SEAMLESSLY: This sleek monitor is virtually bezel-free on three sides, so the screen looks even bigger for the viewer. This minimalistic design also allows for seamless multi-monitor setups that enhance your workflow and boost productivity
  • A BETTER READING EXPERIENCE: For busy office workers, EasyRead mode provides a more paper-like experience for when viewing lengthy documents
phantomjs rasterize.js 'http://en.wikipedia.org/w/index.php?title=Jakarta&printable=yes' jakarta.pdf

Here the example passes a print-oriented Wikipedia URL and names the output jakarta.pdf. The guide identifies PDF as a supported format and presents rasterize.js as a fuller rendering example: PhantomJS screen capture guide. Use the small script above when you want to control navigation handling or page settings directly; use the supplied example when its command-line behavior meets your needs.

Choose a viewport and handle delayed page content

Set the viewport before opening the URL

A site’s responsive layout may depend on the browser window dimensions. Set page.viewportSize before calling page.open so the page lays out at the intended width and height:

Rank #2
Philips 22 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 221V8LB
  • CRISP CLARITY: This 22 inch class (21.5″ viewable) Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
  • 100HZ FAST REFRESH RATE: 100Hz brings your favorite movies and video games to life. Stream, binge, and play effortlessly
  • SMOOTH ACTION WITH ADAPTIVE-SYNC: Adaptive-Sync technology ensures fluid action sequences and rapid response time. Every frame will be rendered smoothly with crystal clarity and without stutter
  • INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
  • THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors
var page = require('webpage').create();
page.viewportSize = { width: 1280, height: 900 };

page.open('https://example.com/', function (status) {
  if (status !== 'success') {
    console.log('Unable to load the address!');
    phantom.exit(1);
    return;
  }

  page.render('page.pdf');
  phantom.exit();
});

The dimensions above are an example, not a universal print setting. Choose a viewport that produces the layout you want; the API defines viewportSize as the dimensions used for layout. See the viewportSize API documentation.

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

Do not assume the load callback means every script has finished

Some pages perform additional work after their initial load event. PhantomJS examples sometimes wait briefly before capture, but a fixed delay is only a timing guess: it cannot guarantee that arbitrary asynchronous content has appeared. If the target site loads important content later, identify a site-specific readiness condition where possible and wait for that rather than relying on a universal sleep interval. The official examples illustrate delayed capture patterns, but do not establish a delay that works for every page: PhantomJS quick start.

Rank #3
Dell 24 Monitor - SE2426H - 23.8-inch FHD (1920x1080) 144Hz 1ms Display, in-Plane Switching (IPS) Technology, AMD FreeSync™, TÜV 3-Star 2X HDMI, Tilt
  • Clear visuals. Fluid motion: A 144Hz refresh rate and 1ms MPRT deliver smooth, tear‑free motion across work, gaming, and streaming for clearer, more fluid viewing.
  • Eye comfort: TÜV Rheinland 3‑star* certification reduces harmful blue light while preserving stunning color quality without compromise. *TÜV Rheinland 3-star eye comfort certification.
  • Wide viewing angle: Get consistent views across a wide 178° /178° viewing angle.
  • In-Plane Switching (IPS): See excellent color accuracy and consistency across wide viewing angles with In-plane Switching (IPS) technology.
  • Ultra-thin bezels: Maximize your viewing experience with thin bezels.

Common problems and fixes

  • The script reports that it cannot load the address. page.open returned fail. Confirm the URL is reachable from the machine running PhantomJS, correct any URL typo, and keep the status check so the script does not render after a failed load.
  • The PDF has the wrong responsive layout. Set page.viewportSize before navigation and adjust its width and height to match the desired layout.
  • Content loaded after the PDF was created is missing. The initial load callback may not represent completion of later asynchronous work. Wait on an appropriate page-specific readiness signal where possible; a short fixed wait may help in some cases but is not reliable for all sites.
  • You are choosing a tool for a new production workflow. The official PhantomJS homepage says development is suspended. Existing scripts may still be useful to maintain, but the project status is a material risk when selecting a rendering engine for new systems.

Or skip the browser setup: ScreenshotNeo

If you need a web capture without installing or maintaining PhantomJS, ScreenshotNeo offers a one-request API that can return a PDF. Its cookie/consent handling accepts banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each cleanup step can be turned off. Bot checks and CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and responses identify page verdict and billing status in headers. ScreenshotNeo also provides an MCP server with take_screenshot, get_page_info, and capture_pdf tools for AI agents.

For PDF output, request the endpoint with the format=pdf option; see the ScreenshotNeo API documentation for current parameters. This cURL example targets the same sample page:

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com/ -d format=pdf -o page.pdf

ScreenshotNeo has a free plan with 1,000 screenshots per month and no card required; paid plans start at $5 for 3,000. Learn about ScreenshotNeo or sign up for 1,000 free screenshots a month, with no card.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
Sale
Samsung 27" Essential S3 (S36GD) Series FHD 1800R Curved Computer Monitor | 100Hz, Game Mode, Advanced Eye Comfort, HDMI and D-sub Ports (LS27D366GANXZA)
  • CURVED FOR ENHANCED ENGAGEMENT: An immersive viewing experience with a curved monitor that wraps more closely around your field of vision; It creates a wider view, enhancing depth perception and minimizing peripheral distraction
  • SMOOTH PERFORMANCE FOR SEAMLESS CONTENT: Stay in the action when playing games, watching videos, or working on creative projects; The 100Hz refresh rate reduces lag and motion blur so you don't miss a thing in fast-paced moments¹
  • MORE GAMING POWER: Gain the edge with optimizable game settings; Color and image contrast can be adjusted to see scenes more vividly and spot enemies hiding in the dark; Game Mode adjusts any game to fill the screen so you can view every detail²
  • KEEP IT EASY ON THE EYES: Care for your eyes and stay comfortable, even during long sessions; Advanced eye comfort technology certified by TÜV reduces eye strain by minimizing blue light and reducing irritating screen flicker²
  • INCREASED VERSATILITY: Connect to more; Plug devices straight into your monitor for increased flexibility, making your computing environment even more convenient
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Frequently Asked Questions

Does PhantomJS support PDF output?

Yes. Its documented rendering workflow supports writing a PDF with page.render.

Is PhantomJS still being developed?

The official PhantomJS homepage states that development is suspended until further notice.

Best Value
Sale
Sceptre New 22-Inch Gaming Monitor, FHD 1080p, Up to 144Hz, HDMI, DisplayPort, Built-in Speakers, Machine Black (E225W-FW144 Series, 2026)
  • 【INTEGRATED SPEAKERS】Whether you're at work or in the midst of an intense gaming session, our built-in speakers provide rich and seamless audio, all while keeping your desk clutter-free.
  • 【EASY ON THE EYES】 Protect your eyes and enhance your comfort with Blue-Light Shift technology. This feature reduces harmful blue light emissions from your screen, helping to alleviate eye strain during long hours of use and promoting healthier viewing habits.
  • 【WIDEN YOUR PERSPECTIVE】Our sleek minimal bezel design ensures undivided attention. The nearly bezel-free display seamlessly connects in a dual monitor arrangement, delivering an unobstructed view that lets you focus on more at once, completely distraction-free.

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 *

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

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair scan

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.