By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,836 Members | 2,059 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,836 IT Pros & Developers. It's quick & easy.

Page Orientation HTML

P: n/a
Since no one can answer the following question:

I have a issue. I need to create a command line application/or windows
application that will take 2
parameters and will print to the default printer without any popups. the
first parameter is the html file name(location) second is a switch that will
tell the app to print in landscape or protrait. Basicly I when I type in
(for example) PrintApp "c:\printthis.html" \L it should print the file
printthis.html in landscape. I have tried everything and I have some apps
that will write but with a prompt and others that will write but it will not
print the html correctly (because I am not rendering it). Does anyone have
any clues?
I need to open the app, Print then close without the user knowing


Can someone please point me in direction of how to change the page
orientation on a html page so it will print in either in portait or
landscape?
Nov 16 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
"Sean McKaharay" <se**@classactweb.com> wrote:
Can someone please point me in direction of how
to change the page orientation on a html page so it
will print in either in portait or landscape?


Printing orientation is not a property of the document; it is a
property of the printer.

I want to do something similar (printing out of the ActiveX Web
browser control), and also haven't found a way to do it in C#. I'd
settle for temporarily changing the default printer's settings, but I
don't know how to do that either... please post back if you find out!

P.
Nov 16 '05 #2

P: n/a
I can help you with the portrait / landscape part, or at least point
you in the right direction.

HTML has no notion of "page orientation." HTML is a markup language
deisnged around flowing text. When you render HTML in a window on your
screen, it just pours the text into the window and lets it wrap
wherever it wraps. (This is an oversimplification: of course HTML has
tables and other constructs that allow you more control than this.
However, the bottom line still stands: "portrait" and "landscape" are
foreign concepts as far as HTML is concerned.)

I was going to tell you that you have to tell the _page_ on which
you're going to render the HTML that it should be either portrait or
landscape, and then, conceptually, "pour" the HTML onto the page, but
in looking over the .NET framework, it may be an academic point.

The Framework provides lots of classes for _creating_ HTML, but nothing
for reading and rendering HTML, that I can see. You may have to have
your program call Internet Explorer through a callable interface
(assuming that it has one) and then see if you can't get IE to render
the pages and print them without also showing up on the screen.

I can see no way of rendering HTML directly by using the .NET framework.

Nov 16 '05 #3

P: n/a
I have the app that can open and print the html but I need to change the way
the page prints out. So basicly I need to print the page 8 1/2 X 11 to 11 X
8 1/2.

"Bruce Wood" <br*******@canada.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
I can help you with the portrait / landscape part, or at least point
you in the right direction.

HTML has no notion of "page orientation." HTML is a markup language
deisnged around flowing text. When you render HTML in a window on your
screen, it just pours the text into the window and lets it wrap
wherever it wraps. (This is an oversimplification: of course HTML has
tables and other constructs that allow you more control than this.
However, the bottom line still stands: "portrait" and "landscape" are
foreign concepts as far as HTML is concerned.)

I was going to tell you that you have to tell the _page_ on which
you're going to render the HTML that it should be either portrait or
landscape, and then, conceptually, "pour" the HTML onto the page, but
in looking over the .NET framework, it may be an academic point.

The Framework provides lots of classes for _creating_ HTML, but nothing
for reading and rendering HTML, that I can see. You may have to have
your program call Internet Explorer through a callable interface
(assuming that it has one) and then see if you can't get IE to render
the pages and print them without also showing up on the screen.

I can see no way of rendering HTML directly by using the .NET framework.

Nov 16 '05 #4

P: n/a
How does your app open and print the HTML? It may have to temporarily
change the printer settings via the PageSettings class, but exactly how
to get a the page settings depends upon how your application is
structured.

Nov 16 '05 #5

P: n/a

public Form1(string[] args)
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//move form off page
this.Location = new Point(-1000, -1000);
this._File = @"c:\PrintMe.html";
// if(args.Length != 0)
// {
// this._File = args[0];
// if((args[1] == @"\l") || (args[1] == @"\L"))
// this._PrintOrientation = "Landscape";
// else if ((args[1] == @"\p") || (args[1] == @"\P"))
// this._PrintOrientation = "Portrait";
// }

this.axWebBrowser1.DocumentComplete +=new AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent Handler(axWebBrowser1_DocumentComplete);
//
// TODO: Add any constructor code after InitializeComponent call
//
this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components);

// The Icon property sets the icon that will appear
// in the systray for this application.
//notifyIcon1.Icon = normalIcon;

// The ContextMenu property sets the menu that will
// appear when the systray icon is right clicked.
notifyIcon1.ContextMenu = this.contextMenu1;

// The Text property sets the text that will be displayed*,
// in a tooltip, when the mouse hovers over the systray i*con.
notifyIcon1.Text = "the text";
notifyIcon1.Visible = true;

//Remove from the taskbar and also from alt+tab
this.WindowState = System.Windows.Forms.FormWindowState.Minimized;
this.Visible = false;
this.axWebBrowser1.Visible = false;
try
{
this.axWebBrowser1.Navigate(this._File);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
int windowStyle = GetWindowLong(Handle, GWL_EXSTYLE);
SetWindowLong(Handle, GWL_EXSTYLE, windowStyle | WS_EX_TOOLWINDOW);

}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components);
this.contextMenu1 = new System.Windows.Forms.ContextMenu();
this.axWebBrowser1 = new AxSHDocVw.AxWebBrowser();
((System.ComponentModel.ISupportInitialize)(this.a xWebBrowser1)).BeginInit();
this.SuspendLayout();
//
// notifyIcon1
//
this.notifyIcon1.Text = "notifyIcon1";
this.notifyIcon1.Visible = true;
//
// axWebBrowser1
//
this.axWebBrowser1.Enabled = true;
this.axWebBrowser1.Location = new System.Drawing.Point(24, 64);
this.axWebBrowser1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.Get Object("axWebBrowser1.OcxState")));
this.axWebBrowser1.Size = new System.Drawing.Size(192, 96);
this.axWebBrowser1.TabIndex = 0;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.axWebBrowser1);
this.Name = "Form1";
this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
this.Text = "Printing...";
((System.ComponentModel.ISupportInitialize)(this.a xWebBrowser1)).EndInit();
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
Application.Run(new Form1(args));
}
private void axWebBrowser1_DocumentComplete(object sender, AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent e)
{
object o = null;
try
{
axWebBrowser1.ExecWB(SHDocVw.OLECMDID.OLECMDID_PRI NT, SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER , ref o, ref o);
axWebBrowser1.CommandStateChange+=new AxSHDocVw.DWebBrowserEvents2_CommandStateChangeEve ntHandler(axWebBrowser1_CommandStateChange);
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
}
private void axWebBrowser1_CommandStateChange(object sender, AxSHDocVw.DWebBrowserEvents2_CommandStateChangeEve nt e)
{
if(this._CommandState != 0)
{
this.axWebBrowser1.Visible = false;
this.ShowInTaskbar = false;
this.axWebBrowser1.Silent = true;
System.Threading.Thread.Sleep(2000);
this.Close();
}
this._CommandState++;
}
}




"Bruce Wood" <br*******@canada.com> wrote in message news:11**********************@c13g2000cwb.googlegr oups.com...
How does your app open and print the HTML? It may have to temporarily
change the printer settings via the PageSettings class, but exactly how
to get a the page settings depends upon how your application is
structured.

Nov 16 '05 #6

P: n/a
Since you're using an Active X control to render and print your HTML,
you have to find some way to tell the control how to orient the print
page.

Unfortunately, I can't find any documentation anywhere on the Web for
the Active X WebBrowser control. I know it's there, but I seem to be in
Google-stupid mode today.

Can anyone point me toward the reference docs for this Active X control?

Nov 16 '05 #7

P: n/a
>Since you're using an Active X control to render and print your HTML,
you have to find some way to tell the control how to orient the print
page.


It's rather tricky, really - I played around with this for quite some
time, and it's really not easy, unfortunately :-( Don't get it - the
whole printing stuff in .NET, and also in the HTML / axWebBrowser
stuff is SOOOO crappy.....

Basically, in the end, what you need to do is create so called "print
templates". If you have an app that hosts a web browser control as an
ActiveX control, you can instruct that ACtiveX to print using a given
print template. Inside that print template, you can then specify
things like page size and paper orientation - but again, that's a
static HTML template page, so you'll need one for portrait and one for
landscape mode - and two each for every paper size you plan to
support. Quite silly, really......

Read more about those print templates and printing from the MS IE
5.x/6.x web control on MSDN:

* Beyond Print Preview: Print Customization for Internet Explorer 5.5
http://msdn.microsoft.com/library/de...intpreview.asp

* Print Preview 2: The Continuing Adventures of Internet Explorer 5.5
Print Customization
http://msdn.microsoft.com/library/en...ttemplate2.asp

* Printing and Style Sheets
http://msdn.microsoft.com/workshop/a...e/printing.asp

Entire section on MSDN devoted to Print Templates in the IE web
browser control:
http://msdn.microsoft.com/workshop/b.../reference.asp

Marc
================================================== ==============
Marc Scheuner May The Source Be With You!
Berne, Switzerland m.scheuner -at- inova.ch
Nov 16 '05 #8

P: n/a
>Since you're using an Active X control to render and print your HTML,
you have to find some way to tell the control how to orient the print
page.


It's rather tricky, really - I played around with this for quite some
time, and it's really not easy, unfortunately :-( Don't get it - the
whole printing stuff in .NET, and also in the HTML / axWebBrowser
stuff is SOOOO crappy.....

Basically, in the end, what you need to do is create so called "print
templates". If you have an app that hosts a web browser control as an
ActiveX control, you can instruct that ACtiveX to print using a given
print template. Inside that print template, you can then specify
things like page size and paper orientation - but again, that's a
static HTML template page, so you'll need one for portrait and one for
landscape mode - and two each for every paper size you plan to
support. Quite silly, really......

Read more about those print templates and printing from the MS IE
5.x/6.x web control on MSDN:

* Beyond Print Preview: Print Customization for Internet Explorer 5.5
http://msdn.microsoft.com/library/de...intpreview.asp

* Print Preview 2: The Continuing Adventures of Internet Explorer 5.5
Print Customization
http://msdn.microsoft.com/library/en...ttemplate2.asp

* Printing and Style Sheets
http://msdn.microsoft.com/workshop/a...e/printing.asp

Entire section on MSDN devoted to Print Templates in the IE web
browser control:
http://msdn.microsoft.com/workshop/b.../reference.asp

Marc
================================================== ==============
Marc Scheuner May The Source Be With You!
Berne, Switzerland m.scheuner -at- inova.ch
Nov 16 '05 #9

P: n/a
Please guys,
Me too am so intrested in printing landscape HTML from AxWebBrowser
control in c#.
I read those topics in MSDN. Everything is getting me straight to what
does every tag do. I cannot get the whole picture. How is the template
file looks like. Should it start with <html> or <?Xml> or what. The
sample link in the MSDN article is broken.
Can anyone give me a listing of a print template to print landscape?
Also I am using:
webView.ExecWB(SHDocVw.OLECMDID.OLECMDID_PRINT,
SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER ,
ref dummy, ref dummy);
to accomplish printing.
Should it work if I only pass the path string instead of the first
dummy? because there is no Exec in the API of AxWebBrowser in my C#
project.

Thanks

*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.