0

With the @page directive, we can specify printer margin of the page (which is not the same as normal css margin of a html element):

<style type="text/css" media="print">
    @page 
    {
        size: auto;   /* auto is the current printer page size */
        margin: 0mm;  /* this affects the margin in the printer settings */
    }        
</style>

Can these values be changed from code behind(C# Code) or javascript?

i.e set size:landscape or size:8.27in 11.69in; and change margin value from code behind(C#) or javascript or jquery.

Veer
  • 1,575
  • 3
  • 16
  • 40

1 Answers1

0

This seems to be inline css (directly in the page). If so, I can`s see any reason you should not be able to just output the values you want to be able to change as variables or properties from C#. Your browser does not know or care how the page is composed, it just accepts the html and other stuff within it - in your case, css.

If you are using external style sheets, you could use different style sheets for each option you want to provide, and then use C# to change the url to the appropriate style sheet as needed.

Yes, you can also change the CSS from java script if you prefer that. I havent tried manipulating@page` directives myself, but I can't see why it should not work. There are several ways to change CSS from JS. For example, a quick search turned up this other answer on SO.

Community
  • 1
  • 1
Kjartan
  • 18,591
  • 15
  • 71
  • 96