I am new to ASP.Net using C#. I want to do a printer friendly page开发者_Python百科 and my system should change the printer orientation to landscape automatically by default. The content includes images and text. I only want to show the content. How can I do this?
You should take a look at CSS for creating print-friendly pages:
<link rel="stylesheet" type="text/css" media="print" href="print.css" />
When you set the media="print"
attribute, you're telling the browser to use that particular stylesheet instead of the regular one. There's a great article on CSS and print on A List Apart, "CSS Design: Going to Print" by Eric Meyer.
And specifically for the landscape page orientation, try this in your CSS:
@page { size: landscape }
Update: Daniel Ballinger was kind enough to point out the size: landscape
attribute isn't supported in the majority of current browsers (if any).
You could try using CSS definitions that actively target printer output using print media. This will allow you to hide or show elements as required.
This can be done with either a reference to a separate style sheet or by using an @media rule within the existing style definitions.
Specify the target medium within the document language
<LINK REL="stylesheet" TYPE="text/css" MEDIA="print" HREF="print.css">
Specify the target medium from a style sheet with the @media or @import at-rules.
@import url("print.css") print;
or
@media print {
/* style sheet for print goes here */
}
I've looked at changing the print orientation in the past and the conclusion I came to was that was outside your ability to control in a website. I.e. there was no solution that worked well for the majority of browsers. See also Is @Page { size:landscape} obsolete?
精彩评论