The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →To increase an iText PDF’s width for HTML, set a wider PageSize before conversion. If the HTML uses responsive CSS, also set pdfHTML’s screen media width to match the page width; otherwise the PDF page can be wide while the HTML still lays out as if it had a narrower viewport. iText does not automatically discover an arbitrary HTML document’s required width or resize a page after layout without further layout work or post-processing.
Choose the right approach before converting
First decide whether the desired width is already known, should be selected by responsive CSS, must be inferred from content, or cannot change because the output has to remain A4, Letter, or another fixed size. These goals use different techniques.
| Approach | Use it when | Tradeoff |
|---|---|---|
Set a custom PageSize before conversion |
You know or can bound the required width. | It does not infer a width from arbitrary HTML; you still need to choose height and pagination behavior. iText responsive Java example. |
| Match the screen media width to the page width | CSS media queries or responsive layout should adapt to the output width. | You must keep the PDF page geometry and CSS viewport consistent. iText responsive Java example. |
Use CSS @page size |
Page dimensions belong in the HTML/CSS. | pdfHTML support is not identical to a browser’s print engine; verify the deployed version. pdfHTML CSS support matrix. |
| Measure content and adjust the page | You need a single page fitted to rendered content. | The official example measures height, not arbitrary content width, and assumes content fits on one page. iText Chapter 4. |
| Scale content onto a fixed page | The final PDF must retain a prescribed page size. | All content, including text, becomes smaller. iText scaling article. |
Set a known dynamic width in Java
The practical default is to calculate or receive a width in your application, create a custom PageSize, and set it on the PdfDocument before calling HtmlConverter. For responsive HTML, configure MediaDeviceDescription as screen media and give it the same intended width. The iText Java example uses this pairing.
The following is a runnable pattern for a project with the iText pdfHTML dependency available. Width and height values passed to PageSize are PDF user units (points); this example assumes your chosen dimensions are expressed in those units. Replace the sample values with values derived from your application and use a destination path that exists.
Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Scan for outdated or missing drivers - takes under a minuteDriver Scan →#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
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 com.itextpdf.styledxmlparser.css.media.MediaDeviceDescription;
import com.itextpdf.styledxmlparser.css.media.MediaType;
import java.io.FileInputStream;
import java.io.IOException;
public class HtmlToWidePdf {
public static void main(String[] args) throws IOException {
float targetWidth = 900f;
float pageHeight = 1200f;
String htmlPath = "input.html";
String pdfPath = "output.pdf";
PageSize pageSize = new PageSize(targetWidth, pageHeight);
ConverterProperties properties = new ConverterProperties();
MediaDeviceDescription media = new MediaDeviceDescription(MediaType.SCREEN);
media.setWidth(targetWidth);
properties.setMediaDeviceDescription(media);
try (PdfWriter writer = new PdfWriter(pdfPath);
PdfDocument pdf = new PdfDocument(writer);
FileInputStream html = new FileInputStream(htmlPath)) {
pdf.setDefaultPageSize(pageSize);
HtmlConverter.convertToPdf(html, pdf, properties);
}
}
}
Check the imports and method signatures against the iText and pdfHTML versions in your project. The official responsive source is on the moving develop branch, so it illustrates the approach rather than pinning behavior to a specific release. For a page width derived from a CSS length, iText’s example uses CssDimensionParsingUtils.parseAbsoluteLength; make sure the resulting unit is appropriate for your PDF page and media width.
Where should the width come from?
- Known report or table width: pass the configured width into the PDF-generation code before conversion.
- Responsive layout: choose a viewport width that triggers the intended CSS breakpoint, then use that width for both the screen media description and page geometry.
- Untrusted or variable content: define a maximum width, or use a measurement/layout pass designed for your content. Do not assume pdfHTML can infer and enlarge the page automatically.
Decide how height should behave
Width and height are separate decisions. A sufficiently wide page can still paginate vertically. Set a conventional height if multiple pages are acceptable; if the output must be one long page, use a deliberate content-height strategy and account for viewer limits.
Use CSS @page when dimensions belong in the document
The pdfHTML support matrix lists @page and its size property—including custom dimensions such as 210mm 297mm—as supported. It also lists width, height, portrait/landscape, and multi-page content as supported. The matrix lists overflow and named-page selection via the page property as unsupported. This is pdfHTML-specific guidance, not a promise of full browser print behavior; check the matrix and output against the version you deploy: iText’s pdfHTML CSS feature support page.
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⁴
Using CSS for page size does not remove the need to think about viewport width. If responsive rules depend on screen media, configure the media description too. When output dimensions are essential, set and verify them through the PDF-generation code rather than relying only on HTML styling.
Recommended Free Tools
Fit a single page to rendered content
iText’s documented one-page report technique addresses content height: it begins with a tall page, converts HTML to a Document, records the final vertical position using a custom line separator, then changes the page media box. The example assumes all content fits on one page. It is not an automatic width-measurement recipe. To determine a width from content, you need an appropriate horizontal measurement or layout strategy for your specific HTML before producing the final page.
The example uses a tall page of 14,400 user units. The iText chapter describes 14,400 user units as an Adobe Acrobat/Reader implementation limit for rendering page width or height; pages beyond that may appear blank in those viewers. Treat that as a viewer constraint, not a universal PDF-format maximum. See iText Chapter 4.
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.
Keep a standard page and scale oversized content
If a downstream workflow requires A4, Letter, or another fixed page size, increasing the final page width is the wrong remedy. iText’s documented alternative is to render the HTML on a page large enough to contain it, copy the rendered page as a PdfFormXObject, then place and scale that object onto the required output page. This preserves the output page size but scales text and graphics together, potentially reducing legibility. Multi-page content also needs an explicit placement and pagination plan. See iText’s scaling guidance.
Troubleshoot clipping, unexpected wrapping, and blank output
- PDF page is wide but the table still wraps: set the screen media width as well as the default page size. Ensure the width corresponds to the CSS breakpoint you intend.
- Content is clipped at the right edge: determine whether the clipping occurs in HTML layout or at the PDF page boundary. Increase the target width before conversion, check CSS fixed widths and margins, and confirm the rendered page’s media box.
- Content unexpectedly moves to multiple pages: page width does not control page height. Increase height only if a longer page is intended; otherwise allow pagination and inspect page breaks.
- Output differs from browser print preview: pdfHTML supports a defined subset of CSS. Check its support matrix for properties such as overflow and named page selection instead of assuming browser equivalence.
- A very large page appears blank in Acrobat or Reader: check whether a dimension exceeds 14,400 user units, the viewer limit described by iText. Reduce the dimensions, paginate, or scale to a conventional page.
- Text is too small after conversion: scaling to fit a fixed-size page shrinks all content. Prefer a wider output page if permitted, or reflow the HTML at a suitable viewport rather than scaling everything down.
Or skip the browser setup
If your actual goal is to capture a web page as an image or PDF rather than generate a report PDF inside iText, ScreenshotNeo offers a one-call screenshot API. This is an alternative workflow, not an iText page-sizing technique.
cURL, with the URL adapted to the page you want:
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 request options. ScreenshotNeo accepts cookie or consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each step can be turned off. Bot checks/CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and responses identify page verdict and billing status in headers. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents using Claude, Cursor, or another MCP client. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 shots.
Sign up for ScreenshotNeo’s free plan to try 1,000 screenshots a month with no card.
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
Further reading
- iText responsive Java example
- iText Chapter 4: adding abstract elements and images
- Scaling large HTML content onto smaller PDF page sizes
- pdfHTML CSS feature support matrix
- Setting a custom page size in pdfHTML
Frequently Asked Questions
Can iText calculate the required PDF width from arbitrary HTML automatically?
The documented examples show choosing a custom width before conversion; they do not establish automatic width discovery for arbitrary HTML. Determine the width with your application’s data or a suitable measurement strategy.
Does changing the PDF page width make HTML content larger?
No. Page dimensions set the available PDF area. Responsive CSS may change layout when the screen media width changes, but merely widening the page does not enlarge fixed-size HTML content.
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.

