Link to home
Start Free TrialLog in
Avatar of vortex99
vortex99

asked on

change page orientation/font size

Is there any way to change the page orientation to landscape for printing with code. Also is there a way to change the font size. Not the font size in the html, but the setting in IE, view menu-> fonts.

Avatar of msdixon
msdixon

not that i'm aware of without some sort of activex object or something like that. it would also be a permissions issue.

i'm interested to see if anyone thinks it can be done.
must be an activeX solution executing at the client
Avatar of Mark Franz
There is a solution for IE 5, I have not tried it with any other versions;

<HTML>
<HEAD>
<OBJECT ID="wbp"
CLASSID="CLSID:778C58A9-81B6-11D3-BB8F-00C04FA3471C">
</OBJECT>
<SCRIPT LANGUAGE="VBScript">
    Sub Print()
        If Len(wbp.DefaultPrinterName) = 0 Then
            MsgBox "No default printer!"
            Exit Sub
        End If
        wbp.Header = "My Header"
        wbp.Orientation = 2 ' Landscape
        wbp.Print
    End Sub
</SCRIPT>
</HEAD>
<BODY>
<INPUT TYPE="BUTTON" VALUE="Print" ONCLICK="Print()">
</BODY>
</HTML>

Good reference here; http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnie55/html/wb_print.asp
looks like an activeX solution...what is the wbp object?
Web Browser Print, delivered with IE3.

I'm doing some research on this right now cause this subject has come up in a discussion with a customer yetserday so I too have a need to know... but right now it looks like a VB or ActiveX solution.

Check out the link I posted, it's full of great info.

The MEDIA attribute allows you to define a CSS style for display on the screen, on a printed document, or both. You can use the MEDIA attribute with the LINK and STYLE elements. Values for MEDIA are SCREEN, PRINT, and ALL. The default is SCREEN, so leaving the MEDIA attribute unspecified causes the style sheet to always be applied to the page for the screen as well as printing. PRINT specifies that the style sheet is used for printing. None of the attributes defined in the PRINT style will be in effect on screen. The ALL value determines that the document is formatted for both the screen and print.

Here is an example that demonstrates using the MEDIA attribute with an inline style. Note that there are two STYLE elements, one with MEDIA="PRINT" and another with MEDIA="SCREEN". The screen version displays white text on a black background, and the printed version displays black text on a white background.

<HTML>
  <HEAD>
    <STYLE MEDIA="PRINT">
      BODY { background-color:white; color:black; }
    </STYLE>
    <STYLE MEDIA="SCREEN">
      BODY { background-color:black; color:white; }
    </STYLE>
  </HEAD>
  <BODY>
    This is a test.
  </BODY>
</HTML>

Here is an example of how you would specify a linked style sheet that applies when printing:

<LINK REL="stylesheet" HREF="print.css" MEDIA="PRINT">

You can also specify custom margins when printing using the margin style properties, but these are offset from the margins specified by the Page Setup margins.

Actually I have posted that link here before for others who have asked this question (just now realized the have altered the URL so i didnt recognize it right off).

It is an activeX solution, but since its from MS, it may be signed/safe but I havent tested it yet.  Does it come up with any prompts informing you of the fact that an activeX control is being used.

The problems you encounter with this is the fact that is is activeX, thus an IE based solution only, and the fact that it does not work on Win2k machines (according to the article).  The most common message given by experts here regarding printing is that you cant, not with HTML.  If you need to control how something is printed, you need to convert the file to a document type where you do have certain control, such as PDF.
I would prefer converting it to a pdf format.
http://www.15seconds.com/issue/990902.htm
http://www.activepdf.com

hongjun
Media or @print options in the HTML don't work with ANYTHING -- no browsers support them.

If it's critical that it print a certain way, make it a PDF. Other than that, it's an exercise in frustation.

If it needs to print landscape, tell the user that. Let them change the orientation -- then they know it's been changed.  
WebWoman, the MEDIA option of Style works just fine in all browsers above IE4, (except Mac, but who cares about Macs anyway);

<STYLE MEDIA="PRINT">
BODY {
     background-color:white;
     color:black;
     font-family : Arial, Helvetica, sans-serif;
     font-size : 10pt;
}
</STYLE>

<BODY>
This is a test print.<p>
<INPUT TYPE="BUTTON" VALUE="Print" ONCLICK="window.print()">

Unfortunately I have been playing with the controls and objects delivered and cannot get the ExecWB to print Landscape, and in IE5 the "DONTPROMPTUSER" call is not valid, it will still show the properties dialog.

Azra, the "wbp" script shown does use a Class object, but since I am no C++ or VB guru, I hope you can provide more input.
Your body style is perfectly valid whether you use a media tag or not (and that's not the proper syntax from everything I've found). Your javascript doesn't use it either.

And if it worked, you'd be able to specify exactly the print settings you wanted, and they'd be applied. But that's not what's happening, is it?

According to the specs, it should be set as an alternative style, with the @media tag or that @page tag. The @media is a paged format... and according to everything I've found, the paged options and alternative styles aren't supported by anything.
@media and @page are CSS2.

You need to try the MEDIA style like I posted, the BODY style is only applied to the PRINT queue, not the page.  With that thought, you could actually do this;

<STYLE MEDIA="PRINT">
BODY {
    background-color:white;
    color:black;
    font-family : Arial, Helvetica, sans-serif;
    font-size : 10pt;
}
</STYLE>
<STYLE>
BODY {
    background-color:black;
    color:white;
    font-family : sans-serif;
    font-size : 12px;
}
</STYLE>


<BODY>
This is a test print.<p>
<INPUT TYPE="BUTTON" VALUE="Print" ONCLICK="window.print()">
</BODY>

The page will be black with white font, the printed page will be white with black font.  The MEDIA tag is not browser friendly though, IE4> only.  No Netscape, (not sure about 6 though), and most certainly not Mac, (at least not IE4 for Mac).



Please check here...
http://www.htmlhelp.com/reference/css/references.html
And note this line...
>>CSS2 provides numerous additions to CSS1, few of which are supported by browsers.
>>

Also check here...
http://richinstyle.com/bugs/table.html
And note the many things (almost everything relating to printing) that aren't supported or don't work.
Right, this works;

<STYLE MEDIA="PRINT">
BODY {
   background-color:white;
   color:black;
   font-family : Arial, Helvetica, sans-serif;
   font-size : 10pt;
}
</STYLE>

@MEDIA does not...
But again... unless you have another style set for body (which isn't supported) why bother? You haven't set anything which is ONLY print oriented.
ASKER CERTIFIED SOLUTION
Avatar of Mark Franz
Mark Franz
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
[points to mgfranz]

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

hongjun
EE Cleanup Volunteer