Hi,

I have solved table margins problem but now, I want to set "Page setup" margins in HTML or CSS. How can we do it? I dont want to set them manually all the time before printing.

Thanks

Dani AI

Generated

Short answer: a webpage cannot force the user's printer "Page setup" dialog or change printer-driver defaults on the client machine. Browser print dialogs and driver limits are controlled by the user and the OS. That said, a print stylesheet with the CSS @page at-rule and @media print can request margins, orientation, and page size. That approach complements (but does not replace) local printer settings; it is the correct tool for controlling printed layout from the page.

Example print rules that help wide tables fit onto paper:

@page {
  size: A4 landscape;
  margin: 8mm; /* browsers/printer drivers may still enforce minimums */
}

@media print {
  table { width: 100%; table-layout: fixed; font-size: 10pt; }
  th, td { padding: 4px; overflow-wrap: break-word; word-break: break-word; }
  tr, thead, tfoot { page-break-inside: avoid; }
  .no-print { display: none !important; }
}

Practical notes and troubleshooting: use table-layout: fixed plus narrower fonts and reduced cell padding to avoid horizontal overflow; allow word breaks on long cells; request landscape via @page size if columns are many. If printed output still clips or margins remain, the browser or printer driver is enforcing hardware minimums — only the user can change those via their print dialog or driver. This addresses ’s wide-table issue, expands on ’s CSS approach, and agrees with that local printer settings are ultimately outside page control.

References: MDN @page (CSS) and MDN print media (@media print) for details and browser behavior:
MDN — @page

Recommended Answers

All 3 Replies

Add below tag between head tag

<style type="text/css">
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
}
-->
</style>

Hi,
I need to set "page setup" settings to print wide tables. Because, when check "print preview" nothing changes, therefore i cant print documents as a want.
Thanks

when you hit ctrl P it will open your printer properties. set the properties you like and save it as that.

There is no css code to set printer settings on your local printer.
This is a local machine issue with your printer settings.

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.