Create Landscape PDFs from Web Pages and APIs
In this article
Creating a landscape PDF from a web page allows you to capture wide data tables, expansive dashboards, and complex visual layouts that would otherwise be cut off or shrunk in a standard portrait orientation. By adjusting the print settings in your browser or configuring the parameters of a headless browser API, you can ensure the output matches the horizontal aspect ratio of the source content.
What You'll Need
- A modern web browser (Google Chrome, Mozilla Firefox, or Microsoft Edge).
- For API methods: A development environment with Node.js installed and a library such as Puppeteer or Playwright.
- An active internet connection to access the target web pages.
Step-by-Step
Using Google Chrome
- Open the web page you wish to convert to PDF.
- Open the Print menu by pressing
Ctrl + P(Windows/Linux) orCmd + P(macOS), or by clicking the three-dot menu in the top right and selecting Print. - In the Print dialog, look for the Destination dropdown and select Save as PDF.
- Locate the Layout setting and change it from Portrait to Landscape.
- Click More settings to adjust the scale if the content still exceeds the page width.
- Click Save and choose your file destination.
Using Mozilla Firefox
- Navigate to the desired web page.
- Press
Ctrl + P(Windows/Linux) orCmd + P(macOS). - In the print preview pane on the right, find the Orientation section.
- Select the Landscape radio button.
- Ensure the destination is set to Save to PDF.
- Adjust the Scale percentage if the page elements are not fitting correctly within the landscape boundaries.
- Click Save to export the document.
Using Microsoft Edge
- Open the target web page in Edge.
- Press
Ctrl + P(Windows/Linux) orCmd + P(macOS). - Under the Printer dropdown, select Save as PDF.
- Find the Layout option and select Landscape.
- Use the Scale option under More settings to fine-tune how the content fills the page.
- Click Save to finish.
Using an API (Puppeteer/Node.js)
- Initialize a new Node.js project and install Puppeteer using
npm install puppeteer. - Create a script that launches a headless browser instance.
- Use
page.goto('URL')to navigate to the specific web page. - Call the
page.pdf()function. - Within the options object of the
pdf()method, set thelandscapeproperty totrue. - Specify the
format(e.g., 'A4' or 'Letter') and thepathwhere the file should be saved. - Run the script using
node your-script-jsto generate the landscape PDF.
Common Mistakes
- Ignoring the Scale Setting: Simply switching to landscape may not be enough if the website has a fixed width. Failing to adjust the scale often results in content being clipped on the right side.
- Printing the "Print Version": Some websites serve a different, simplified CSS for printing. If the landscape layout looks wrong, check if the site has a specific print stylesheet that overrides your browser settings.
- Forgetting Background Graphics: By default, many browsers disable background colors and images to save ink. This can make a landscape PDF look empty or broken.
- API Timeout: When using an API, attempting to generate a PDF before the page's JavaScript has fully rendered the content can result in a blank or incomplete landscape document.
Tips
- Enable Background Graphics: In the "More settings" menu of any browser, check the box for Background graphics to ensure the PDF looks exactly like the website.
- Use Custom Paper Sizes: If the content is extremely wide (like a massive spreadsheet), use the API method to define a custom
widthandheightinstead of standard A4 landscape. - Wait for Network Idle: In Puppeteer, use
waitUntil: 'networkidle0'in yourgotocommand to ensure all images and scripts are loaded before the PDF is generated. - Inspect CSS: If you have control over the website, use the CSS rule
@page { size: landscape; }to force the browser to default to landscape mode.
Troubleshooting
If the PDF is still appearing in portrait mode despite your settings, first clear your browser cache or try an Incognito/Private window to ensure no extensions are interfering with the print dialog. If content is being cut off even in landscape, navigate to More settings and change the Scale from "Default" to "Custom," then lower the percentage (e.g., to 80% or 70%) until the content fits.
For API users, if the resulting PDF is blank, verify that the page does not require authentication. If it does, you must handle cookies or login headers before calling the PDF function. Additionally, ensure that the landscape: true property is placed inside the options object and not as a standalone argument.
Frequently Asked Questions
Can I convert a PDF back to portrait after saving it as landscape?
You cannot change the actual dimensions of the saved PDF content without using a PDF editor to crop or rotate the pages, but you can change the view settings in your PDF reader.
Why does the landscape PDF look different from the web page?
This is usually due to the website's "Print CSS," which instructs the browser to hide certain elements (like navigation bars) or change fonts when printing.
Does using an API provide better quality than browser printing?
API methods like Puppeteer provide more control over the exact dimensions, margins, and rendering triggers, making them superior for automated, high-precision reports.
Which browser is best for landscape PDFs?
Chrome and Edge (both Chromium-based) generally offer the most consistent scaling and layout options for converting complex web pages to PDF.
Can I automate landscape PDFs for multiple pages?
Yes, using the API method (Puppeteer or Playwright) allows you to loop through a list of URLs and save each one as a landscape PDF automatically.