Hello,

I came across a nice API called iText which is able to produce PDF-documents from my java-code, this API makes it also possible to create an HTML document.
I want these document to look the 'same', as far as possible.
And I am satisfied with the look.

What I would like to do though is to let the table fill out my
page when I hit the Print button, Am I able to do that ?
Can I set my HTML document or Table to be exactly as wide and as long as an A4-doc ?

best regards, i

Dani AI

Generated

Following 's question about getting an HTML table to fill an A4 print page, and the quick suggestions from (CSS sizing) and (printer tools), the practical options and pitfalls are summarized below.

For browser printing: prefer a print stylesheet and the @page rule so the UA knows the target paper size. Absolute print units (mm) map to physical paper better than px. Common useful rules are setting @page size to A4, using box-sizing so padding and borders are counted, forcing the table to 100% of the content box, repeating headers, and avoiding row breaks inside important rows.

@media print {
  @page { size: A4; margin: 10mm; }
  html, body { margin: 0; }
  .sheet { box-sizing: border-box; width: 210mm; height: 297mm; padding: 10mm; }
  table { width: 100%; table-layout: fixed; border-collapse: collapse; }
  thead { display: table-header-group; }
  tfoot { display: table-footer-group; }
  tr { break-inside: avoid; page-break-inside: avoid; }
}

Cautions and browser limits: many browsers add headers/footers and impose minimum printable margins that CSS cannot override. Print dialog scaling (fit-to-page) can resize output; use print preview and set scale to 100% to test true layout. If exact physical dimensions are required, server-side PDF generation gives more consistent results because the page size can be set explicitly in the PDF API and converters typically honor mm units.

Troubleshooting checklist:

  • Test with "Save as PDF" from the browser to isolate CSS effects.
  • Verify print scale is 100% and "print backgrounds" is enabled if colors matter.
  • Measure the PDF output physically if exact height is required; adjust margins and padding accordingly.
  • For repeated headers across pages use thead as shown; for tables that must not split, avoid page breaks inside rows and consider splitting logical groups into separate tables.

References: MDN on the @page rule and paged media for print CSS details (@page - MDN, Paged media - MDN) and CSS absolute units (length units - MDN).

Recommended Answers

All 2 Replies

Member Avatar for Member #114696

with HTML there's no problem, i suppose if so use can use some good softwares somtimes shipped with your priter such as Cannon WebPrint. With pdf make sure that the dimensions is matching with the page if it is check borders in the print option

It depends on the structure of your HTML. It is possible to size container elements, such as tables and DIVs, using CSS.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.