Page Orientation HTML

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sean McKaharay

    Page Orientation HTML

    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.h tml" \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?


  • Paul E Collins

    #2
    Re: Page Orientation HTML

    "Sean McKaharay" <sean@classactw eb.com> wrote:
    [color=blue]
    > 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?[/color]

    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.


    Comment

    • Bruce Wood

      #3
      Re: Page Orientation HTML

      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 oversimplificat ion: 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.

      Comment

      • Sean McKaharay

        #4
        Re: Page Orientation HTML

        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" <brucewood@cana da.com> wrote in message
        news:1107283193 .754586.28420@f 14g2000cwb.goog legroups.com...[color=blue]
        >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 oversimplificat ion: 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.
        >[/color]


        Comment

        • Bruce Wood

          #5
          Re: Page Orientation HTML

          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.

          Comment

          • Sean McKaharay

            #6
            Re: Page Orientation HTML


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

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

            this.axWebBrows er1.DocumentCom plete +=new AxSHDocVw.DWebB rowserEvents2_D ocumentComplete EventHandler(ax WebBrowser1_Doc umentComplete);
            //
            // TODO: Add any constructor code after InitializeCompo nent call
            //
            this.notifyIcon 1 = new System.Windows. Forms.NotifyIco n(this.componen ts);

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

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

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

            //Remove from the taskbar and also from alt+tab
            this.WindowStat e = System.Windows. Forms.FormWindo wState.Minimize d;
            this.Visible = false;
            this.axWebBrows er1.Visible = false;
            try
            {
            this.axWebBrows er1.Navigate(th is._File);
            }
            catch (Exception ex)
            {
            Console.WriteLi ne(ex.Message);
            }
            int windowStyle = GetWindowLong(H andle, GWL_EXSTYLE);
            SetWindowLong(H andle, GWL_EXSTYLE, windowStyle | WS_EX_TOOLWINDO W);

            }
            /// <summary>
            /// Clean up any resources being used.
            /// </summary>
            protected override void Dispose( bool disposing )
            {
            if( disposing )
            {
            if (components != null)
            {
            components.Disp ose();
            }
            }
            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 InitializeCompo nent()
            {
            this.components = new System.Componen tModel.Containe r();
            System.Resource s.ResourceManag er resources = new System.Resource s.ResourceManag er(typeof(Form1 ));
            this.notifyIcon 1 = new System.Windows. Forms.NotifyIco n(this.componen ts);
            this.contextMen u1 = new System.Windows. Forms.ContextMe nu();
            this.axWebBrows er1 = new AxSHDocVw.AxWeb Browser();
            ((System.Compon entModel.ISuppo rtInitialize)(t his.axWebBrowse r1)).BeginInit( );
            this.SuspendLay out();
            //
            // notifyIcon1
            //
            this.notifyIcon 1.Text = "notifyIcon 1";
            this.notifyIcon 1.Visible = true;
            //
            // axWebBrowser1
            //
            this.axWebBrows er1.Enabled = true;
            this.axWebBrows er1.Location = new System.Drawing. Point(24, 64);
            this.axWebBrows er1.OcxState = ((System.Window s.Forms.AxHost. State)(resource s.GetObject("ax WebBrowser1.Ocx State")));
            this.axWebBrows er1.Size = new System.Drawing. Size(192, 96);
            this.axWebBrows er1.TabIndex = 0;
            //
            // Form1
            //
            this.AutoScaleB aseSize = new System.Drawing. Size(5, 13);
            this.ClientSize = new System.Drawing. Size(292, 266);
            this.Controls.A dd(this.axWebBr owser1);
            this.Name = "Form1";
            this.StartPosit ion = System.Windows. Forms.FormStart Position.Manual ;
            this.Text = "Printing.. .";
            ((System.Compon entModel.ISuppo rtInitialize)(t his.axWebBrowse r1)).EndInit();
            this.ResumeLayo ut(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_D ocumentComplete (object sender, AxSHDocVw.DWebB rowserEvents2_D ocumentComplete Event e)
            {
            object o = null;
            try
            {
            axWebBrowser1.E xecWB(SHDocVw.O LECMDID.OLECMDI D_PRINT, SHDocVw.OLECMDE XECOPT.OLECMDEX ECOPT_DONTPROMP TUSER, ref o, ref o);
            axWebBrowser1.C ommandStateChan ge+=new AxSHDocVw.DWebB rowserEvents2_C ommandStateChan geEventHandler( axWebBrowser1_C ommandStateChan ge);
            }
            catch(Exception ex)
            {
            Console.WriteLi ne(ex.Message);
            }
            }
            private void axWebBrowser1_C ommandStateChan ge(object sender, AxSHDocVw.DWebB rowserEvents2_C ommandStateChan geEvent e)
            {
            if(this._Comman dState != 0)
            {
            this.axWebBrows er1.Visible = false;
            this.ShowInTask bar = false;
            this.axWebBrows er1.Silent = true;
            System.Threadin g.Thread.Sleep( 2000);
            this.Close();
            }
            this._CommandSt ate++;
            }
            }










            "Bruce Wood" <brucewood@cana da.com> wrote in message news:1107287124 .137846.242040@ c13g2000cwb.goo glegroups.com.. .[color=blue]
            > 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.
            >[/color]

            Comment

            • Bruce Wood

              #7
              Re: Page Orientation HTML

              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?

              Comment

              • Marc Scheuner [MVP ADSI]

                #8
                Re: Page Orientation HTML

                >Since you're using an Active X control to render and print your HTML,[color=blue]
                >you have to find some way to tell the control how to orient the print
                >page.[/color]

                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


                * Print Preview 2: The Continuing Adventures of Internet Explorer 5.5
                Print Customization
                Find official documentation, practical know-how, and expert guidance for builders working and troubleshooting in Microsoft products.


                * Printing and Style Sheets
                Find official documentation, practical know-how, and expert guidance for builders working and troubleshooting in Microsoft products.


                Entire section on MSDN devoted to Print Templates in the IE web
                browser control:
                Find official documentation, practical know-how, and expert guidance for builders working and troubleshooting in Microsoft products.


                Marc
                =============== =============== =============== =============== ====
                Marc Scheuner May The Source Be With You!
                Berne, Switzerland m.scheuner -at- inova.ch

                Comment

                • Marc Scheuner [MVP ADSI]

                  #9
                  Re: Page Orientation HTML

                  >Since you're using an Active X control to render and print your HTML,[color=blue]
                  >you have to find some way to tell the control how to orient the print
                  >page.[/color]

                  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


                  * Print Preview 2: The Continuing Adventures of Internet Explorer 5.5
                  Print Customization
                  Find official documentation, practical know-how, and expert guidance for builders working and troubleshooting in Microsoft products.


                  * Printing and Style Sheets
                  Find official documentation, practical know-how, and expert guidance for builders working and troubleshooting in Microsoft products.


                  Entire section on MSDN devoted to Print Templates in the IE web
                  browser control:
                  Find official documentation, practical know-how, and expert guidance for builders working and troubleshooting in Microsoft products.


                  Marc
                  =============== =============== =============== =============== ====
                  Marc Scheuner May The Source Be With You!
                  Berne, Switzerland m.scheuner -at- inova.ch

                  Comment

                  • Bishoy Adel

                    #10
                    Re: Page Orientation HTML

                    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.OLECMDI D.OLECMDID_PRIN T,
                    SHDocVw.OLECMDE XECOPT.OLECMDEX ECOPT_DONTPROMP TUSER,
                    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 ***

                    Comment

                    Working...