Click here to Skip to main content
15,920,005 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi,
How can I print some text by reducing the size of the paper in the code rather than reducing it in printer options?
Posted
Comments
ZurdoDev 3-Jun-15 16:38pm    
What code do you have so far? Click Improve question and post the relevant code.
Sergey Alexandrovich Kryukov 3-Jun-15 18:13pm    
This is a reasonable and clear question, if you think at it. Please see Solution 1.
—SA
Sergey Alexandrovich Kryukov 3-Jun-15 18:14pm    
Even though I want to ask "What have you tried so far?", I think I have to up-vote this question. It really makes sense. Please see my answer.
—SA

1 solution

One way to do so would be preparing special "printer version" of the document/page. But having a separate version of the page accessible via an anchor is considered bad style these days; besides it could be addition maintenance burden. And this is because there is a much more suitable, modern way of doing such things: you can define CSS which creates different layout and other style properties for different media, in this case, for screen and sprinter views at the content.

And this is a very reasonable, useful feature, not just for the sake of saving paper and other environmental benefits. For simple content, this would be pointless, but for more complicated designs it could be really important. Look at the page with some buttons, list boxes and other controls. Who need them in the print? They won't be able to click them on the paper. On-screen features can be fundamentally different from the print. So, how to make the styles different, and also to hide some unwanted elements and show others?

This is done using Media Types and the @media rules in CSS: http://www.w3.org/TR/CSS21/media.html[^].

Basically, you can create two or three branches of your CSS rules, some only for screen, some only for printer, some for both. This is how:
CSS
@media print {
    /* rules for printer only */
}
@media screen {
    /* rules for screen only */
}
@media screen, print {
    /* rules for both screen and printer */
}

Moreover, you can easily debug such stylesheet on the browser. You don't need to print it all the time for testing; browser's print preview will show you the effect of your styles.

—SA
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900