Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adjusting page margins for printing

Status
Not open for further replies.

DotNetter

Programmer
May 19, 2005
194
US
In thread216-709289, "mwolf00" posted the following code
Code:
<style media="print">
  body {margin: .18in;}
</style>
How can I use that in my ASP.NET code?

Thanks!
Dot
 
...sorry - I should have explained what it is that I'm trying to do with this code: I am trying to set the print margins programmatically. I do have a CSS in my project. Will that help?

(Baffled...)

Thanks!
Dot
 
Sorry, still not getting it. Are you trying to print on the client programmatically, or just set print margins on the page programmatically (ie, based on some dynamic content) leaving the actual printing to the user?

________________________________________
Andrew
 
Andrew,

There's a (JavaScript) print button on the screen. When the user clicks that, a [tt]Window.print()[/tt] is executed and a print dialogue box pops up. I do not want to make the users change their margins manually each time. I would like it to change their margins at that point - right before they print that screen.

Thanks,
Dot
 
Any stylesheet rules that are declared in a specific media section are only applied to that media. Hence, if you set margins in a print media, it will only affect the page when printing (and something like print-preview). So you don't have to programmatically change them at time of printing, just set them when you send the page to the client under a media section for print.

Note that these aren't printer page margins, they're just like margins for how the content is displayed in a browser, but instead of a window, it's paper. If you're trying to increase margins, that will probably work fine, but decreasing likely won't. There may be client-side scripting ways to change formal page margins, but I don't know how. I think that's beyond what CSS can do (though I could be wrong, anyone to support or refute?).

________________________________________
Andrew
 
I actually do need to decrease the margins...

Any ideas how to do this, anyone?

Thanks!
Dot
 
<style media="print">
body {margin: <%=TheVal%>;}
</style>


declare TheVal the codebehind file...

Known is handfull, Unknown is worldfull
 
Printer settings are firmly in the domain of "user controlled". The only thing that JavaScript's print() method does, is relay the request to the browser, which relays the request to the OS, which opens a Print Dialog.

This is as it should be. I don't want a web page altering settings to my printer, changing the orientation, silently printing, etc.

The CSS "print" settings are not widely supported. And as pointed out, all they do is affect the placement/appearance of the CONTENT within the context of the current media. The user sets that context.

Think in terms of the default "media", the browser window. I can position my window on my screen wherever I like it. The margins and positions of the page elements relate to the window, not the screen.

I know, I know - you can write JavaScript to change the position of the window on the screen and resize the browser window and so on. ALL of which is EVIL :).



Thomas D. Greer

Providing PostScript & PDF
Training, Development & Consulting
 
I have a very predicatable environment for my user base: everyone's running Windows XP Pro with the latest IE with the latest patches.

Any ideas with that info?

Thanks again,
Dot
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top