Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.
Use iText pdfHTML and set the page geometry to landscape before conversion. You can put @page { size: A4 landscape; } in the stylesheet, or create a PdfDocument and call setDefaultPageSize(PageSize.A4.rotate()). The CSS approach keeps print layout with the template; the PDF-document approach lets application code impose the paper size. Both are documented iText patterns, but verify method signatures and feature support against the pdfHTML and iText Core versions you select.
What you need
- A Java (or .NET) project with compatible iText Core and pdfHTML dependencies. Select the two versions as a pair; the documentation cited here does not establish one universally correct current pair.
- Your HTML, stylesheet, images, and fonts available to the converter.
- A writable output stream or file.
pdfHTML is iText’s HTML/CSS-to-PDF add-on and HtmlConverter is its principal conversion API. See the official conversion tutorial and the pdfHTML product page for the dependency and overload model.
Method 1: Set landscape in CSS
Use CSS paged media when the HTML template owns its print presentation. Add this rule to the stylesheet supplied to pdfHTML:
Free tools Windows power users keep installed
One-click scans. No signup required.
@page {
size: A4 landscape;
margin: 12mm;
}
The cited iText feature matrix reports support for @page, the size property, and the portrait/landscape keywords for pdfHTML 6.3.3 paired with iText Core 9.7.0. That is a version-scoped statement, not a guarantee for every later release; check the current matrix before shipping.
#1 Best Overall
- INNOVATIVE CARTRIDGE-FREE PRINTING — No more dealing with lots of tiny ink cartridges; With this wireless document and photo printer each ink bottle set is equivalent to about 90 individual cartridges²
- LESS FREQUENT INK REPLACEMENT — Replacement ink bottles don't have to be changed nearly as often as ink cartridges¹; When you choose this combination printer, scanner and copier you can print up to 4,500 pages black/7,500 color³
- COLOR PRINTING — Up to 2 years of ink in the box4 (and with every replacement ink set) for fewer out-of-ink frustrations
- ZERO CARTRIDGE WASTE — By using an Epson EcoTank printer you can help reduce the amount of cartridge waste ending up in landfills
- HOME PRINTER DESIGNED FOR RELIABILITY — The Epson EcoTank ET-2800 All-in-One Supertank Color Printer creates vivid, detailed prints and documents thanks to Micro Piezo Heat-Free Technology; Fire off 10 ISO pages per minute1 to easily finish large jobs
Complete Java example
import com.itextpdf.html2pdf.ConverterProperties;
import com.itextpdf.html2pdf.HtmlConverter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
public class HtmlToLandscapePdf {
public static void main(String[] args) throws Exception {
ConverterProperties properties = new ConverterProperties();
// Resolve relative CSS, images, and fonts from this directory.
properties.setBaseUri("/absolute/path/to/web-assets/");
try (FileInputStream html = new FileInputStream("report.html");
FileOutputStream pdf = new FileOutputStream("report-landscape.pdf")) {
HtmlConverter.convertToPdf(html, pdf, properties);
}
}
}
In report.html, link your CSS normally or embed the @page rule. The base URI is important when markup contains relative URLs such as css/print.css, images/chart.png, or web fonts. The tutorial demonstrates configuring ConverterProperties and a base URI.
Method 2: Set the PDF document’s default page size
Choose this route when the calling application, rather than the template, must control paper dimensions. Rotate a standard page size before conversion:
import com.itextpdf.html2pdf.ConverterProperties;
import com.itextpdf.html2pdf.HtmlConverter;
import com.itextpdf.kernel.geom.PageSize;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import java.io.FileInputStream;
public class HtmlToLandscapePdfByCode {
public static void main(String[] args) throws Exception {
ConverterProperties properties = new ConverterProperties();
properties.setBaseUri("/absolute/path/to/web-assets/");
try (PdfWriter writer = new PdfWriter("report-landscape.pdf");
PdfDocument document = new PdfDocument(writer);
FileInputStream html = new FileInputStream("report.html")) {
document.setDefaultPageSize(PageSize.A4.rotate());
HtmlConverter.convertToPdf(html, document, properties);
}
}
}
The iText page-size example demonstrates setDefaultPageSize(...) as the control point. The exact combined snippet above is illustrative, so confirm constructors, close behavior, and overloads against the release you install.
Other paper sizes and margins
Replace PageSize.A4.rotate() with another iText PageSize rotated to landscape, or define a custom width and height. With CSS, change A4 to the paper format your print workflow requires and set margins in the same @page block. Keep one owner for geometry where possible: conflicting CSS and document defaults can make troubleshooting harder.
Choosing between CSS and Java configuration
| Question | CSS @page |
PdfDocument default size |
|---|---|---|
| Who owns print layout? | The HTML/CSS template | The application invoking conversion |
| Best fit | Templates reused by designers or multiple converters | Services that impose a standard output format |
| Typical control | Paper keyword, orientation, margins, print rules | Exact page dimensions before conversion |
| Watch for | CSS support varies by pdfHTML version | Template rules may still affect margins and breaks |
Neither route is universally preferable. Compare the paper format, margins, page breaks, overflow, and resource resolution in the actual documents you generate.
Use the right HtmlConverter overload
iText examples show conversion from a string, file, or stream, and distinguish convertToPdf() from convertToDocument(). Use convertToPdf() when you only need the finished file. Use convertToDocument() when subsequent code must work with the layout document before it is closed. The public API page available for reference is specifically pdfHTML 5.0.4; treat it as API-shape documentation, not a current dependency recommendation.
Rank #2
- CARTRIDGE-FREE PRINTING — Print lab-quality photos, graphics and creative projects; Get vibrant colors and sharp text with Epson's high-accuracy printhead and Claria ET Premium 6-color inks
- INK BOTTLES — Save on photos1 and creative projects with affordable in-house printing; All-in-one printer allows you to print 4" x 6" photos for about 4 cents each vs. 40 cents with traditional ink cartridges1
- LESS FREQUENT INK REPLACEMENT — Replacement ink bottles don't have to be changed nearly as often as ink cartridges¹; Printer, scanner and copier lets you print up to 6,200 color pages³
- PRINT FOR LONGER — Up to 2 years of ink in the box² (and with every replacement ink set) for fewer out-of-ink frustrations with this wireless printer
- ZERO CARTRIDGE WASTE — Epson EcoTank printer helps reduce the amount of cartridge waste ending up in landfills; Cartridge-free printer uses high-yield ink bottles; Each replacement ink bottle set is equivalent to about 100 individual ink cartridges⁴
String input
String html = "<html><head>" +
"<style>@page { size: A4 landscape; }</style>" +
"</head><body><h1>Report</h1></body></html>";
HtmlConverter.convertToPdf(html, new PdfWriter("report.pdf"));
For production templates, prefer a stream or file and configure a base URI rather than concatenating large strings.
Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →HTML and CSS limits that affect landscape output
JavaScript is not executed
pdfHTML parses HTML and CSS; it does not run JavaScript. If a chart, table, or other content appears only after script execution, first render or preprocess the page with a browser engine, then pass the resulting HTML to iText. iText explains this requirement in its browser-engine guidance.
CSS is not browser-complete
Landscape support does not imply browser-equivalent rendering. Consult the pdfHTML feature matrix for the CSS features used by your document. Test flex, grid, positioned elements, page-break rules, generated content, and font behavior rather than assuming a browser screenshot predicts the PDF.
Resources and fonts
Resolve every relative URL through setBaseUri, use accessible file or HTTP resources appropriate to your deployment, and verify that the runtime can read them. Missing fonts can change line wrapping and push a wide table onto additional pages.
A validation checklist
- Open the generated PDF and confirm the media dimensions are landscape, not merely that content appears rotated.
- Check the widest table, long URLs, code blocks, and images for clipping at both page edges.
- Inspect page breaks, headers, footers, and repeated table headings.
- Verify that every image, stylesheet, and font loaded from a relative path.
- Compare a representative document at the target paper size and printer margins.
- Repeat the test after upgrading either iText Core or pdfHTML, because feature support is version-specific.
Troubleshooting common failures
The PDF is portrait
Confirm that the CSS containing @page is actually loaded and that the selector is valid. If your service must enforce orientation, set document.setDefaultPageSize(PageSize.A4.rotate()) before conversion. Also verify that you are not inspecting an old output file.
Images or CSS are missing
Set an absolute, correct base URI and ensure the process has permission to read it. Relative URLs are resolved from that base, not from your shell’s current directory.
Rank #3
- SET IT UP ONCE AND PRINT WITH CONFIDENCE. No complicated maintenance. Just easy, reliable printing you can count on.
- INK FOR YEARS. NOT MONTHS. Up to 2 years of ink included. Get thousands of pages of cartridge-free printing. More pages, less hassle
- KEEPS PRINTING WELL AFTER COMPETITORS HAVE QUIT. No complex maintenance. Sharper text, richer colors.[2] Only with HP Smart Tank
- PREMIUM SUPPORT - Strong technical expertise to solve issues faster
- THE LAST PRINTER YOU'LL EVER NEED. Enjoy years of refillable, cartridge-free printing.
Content is clipped or unexpectedly paginated
Reduce page margins, constrain oversized fixed-width elements, and check unsupported CSS in the feature matrix. A landscape page is wider but still has finite printable width; long unbreakable strings and fixed pixel widths can overflow.
Dynamic content is blank
Because pdfHTML does not execute JavaScript, capture the post-rendered HTML with a browser engine or server-side data expansion first.
Compilation errors after an upgrade
Check that Core and pdfHTML versions are compatible and compare the selected release’s API documentation with your imports and overload. Do not copy a method signature from the 5.0.4 API page without checking your installed version.
Performance, reliability, and operational notes
- Reuse immutable template data and avoid repeatedly downloading the same resources in one job; resource access is often the slowest part of conversion.
- Use streams for large HTML files instead of building several full in-memory copies.
- Set explicit timeouts and isolate untrusted input when your application fetches remote resources; a converter should not be allowed to access arbitrary internal URLs.
- Keep a golden HTML fixture and compare page count, dimensions, and visual output in CI after dependency changes.
- Record the iText Core/pdfHTML versions with each generated artifact so a rendering difference can be traced.
These practices improve repeatability, but they do not replace inspection of the actual PDF. The official feature documentation is a capability matrix, not a guarantee that every browser-authored layout will match.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Or skip the browser setup
If your real goal is a clean image or PDF of a live web page rather than server-side HTML-to-PDF composition, ScreenshotNeo provides a single screenshot API request. It accepts consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each cleanup step can be disabled. Bot checks, CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and the response identifies the result with X-Page-Verdict and X-Billed headers. Its MCP server exposes take_screenshot, get_page_info, and capture_pdf to Claude, Cursor, and other MCP clients.
One-call examples
See the ScreenshotNeo documentation for the current parameter list and response details.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
The Free plan includes 1,000 screenshots per month with no card. Paid plans start at $5 for 3,000 shots; every feature is included on every plan. Create a free ScreenshotNeo account.
Rank #4
- Wireless Bluetooth Printer: Portable thermal printer compatible with iPhone, Android phones, iPad and tablet computers via Bluetooth. For smartphones, please download the "Nada Print" App. You can also connect to laptops and computers for printing using a USB-C cable. (Note: Laptops and computers can only be connected via USB and require the installation of a driver first. Bluetooth connection is not supported.)
- No-ink printing: Only supports US Letter and A4 size thermal paper.(Doesn't support regular paper) The no-ink portable thermal printer uses direct thermal technology, requiring no ink, toner or ribbons, making it environmentally friendly, cost-effective and time-saving. The thermal printer package comes with a roll of US Letter thermal printing paper. Note: When installing the paper, remember to switch the paper size switch on APP
- Clear Print: NDYIN N80 portable thermal printer adopts high-definition printing technology, with a 203DPI resolution to provide you with clear printing results. This mobile printer is compatible with roll paper, folded paper and tattoo transfer paper, supporting printing from your mobile phone PDF, Word, pictures and web pages anytime and anywhere. It is recommended to use our NDYIN thermal paper to achieve good printing quality
- Portable wireless printer for travel: The thermal printer is equipped with a built-in 1500mAh rechargeable battery, which can print 160 sheets of 8.5" x 11" thermal paper after being fully charged. It weighs only 1.5 pounds and is compact in size. This ink-free portable printer can be easily carried in a backpack or briefcase! It is perfect for business travel, cars, small offices, construction sites, schools and homes. You can print documents, contracts, invoices and boarding passes anytime and anywhere
- The N80 thermal printer has a wide range of uses. The package includes the N80 printer, a roll of US Letter paper(7m/roll), a user manual, a guide card, a type-C soft cable and a type C adapter. Note: The charging adapter is not included. Special thermal paper is required for use; ordinary paper cannot be used. This ink-free portable thermal printer is suitable for various scenarios such as home, school, travel, office, and outdoor, meeting the printing needs of different groups of people. This tattoo template printer is also compatible with tattoo transfer paper, making it an ideal choice for tattoo art
FAQ
Can I use a custom landscape size?
Yes. Define the dimensions in CSS paged media or provide a custom landscape page size to the PdfDocument; validate the resulting dimensions with your print workflow.
Does landscape orientation make unsupported CSS work?
No. Orientation and CSS feature coverage are separate concerns. Check the versioned feature matrix for each layout feature you depend on.
Which iText version should I install?
The cited feature statement covers pdfHTML 6.3.3 with iText Core 9.7.0. Treat that as the documented scope and verify the current compatible pair for a new project.
Frequently Asked Questions
Can I use a custom landscape size?
Yes. Define the dimensions in CSS paged media or provide a custom landscape page size to the PdfDocument; validate the resulting dimensions with your print workflow.
Recommended Free Tools
Does landscape orientation make unsupported CSS work?
No. Orientation and CSS feature coverage are separate concerns. Check the versioned feature matrix for each layout feature you depend on.
Which iText version should I install?
The cited feature statement covers pdfHTML 6.3.3 with iText Core 9.7.0. Treat that as the documented scope and verify the current compatible pair for a new project.
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.

