Home >Web Front-end >CSS Tutorial >How Can I Reliably Print Landscape from HTML?
Printing Landscape from HTML: Options and Limitations
Printing a report in landscape orientation is sometimes necessary due to the large number of columns. If you want to implement this functionality without requiring users to manually adjust the document settings, CSS provides a potential solution. However, browser support for this solution is inconsistent.
CSS Option
In CSS, you can set the @page property to specify the landscape orientation:
@media print {@page {size: landscape}}
Browser Support
The @page property is part of the CSS 2.1 specification, but the "size" attribute is not fully supported by browsers. In theory, it can set both the page size and orientation, but browsers tend to have mixed support for this feature.
Workarounds
If the @page property is not supported, there are several workarounds available:
Conclusion
Implementing landscape printing from HTML using CSS can be straightforward in some browsers, but support is inconsistent across different browsers. Workarounds such as JavaScript, content rotation, or PDF creation can provide alternative solutions depending on the browser and content. Google Documents addresses this limitation by automatically generating a PDF for printing, allowing for seamless landscape printing in most cases.
The above is the detailed content of How Can I Reliably Print Landscape from HTML?. For more information, please follow other related articles on the PHP Chinese website!