none
Printing HTML documents silent RRS feed

  • Question

  • Hi,

    Does anyone have any experience with printing HTML documents silently? We are trying to print the HTML documents via Word 2003, which is acceptable for us, but we have to strip certain HTML tags. If we do not strip these tags (like <input> and <img>) we are getting big red crosses after importing it in Word and thus on the print also.

    Hope somebody can point me in the right direction.

    Friday, November 11, 2011 9:50 AM

Answers

  • Hi,

    You could use a Browser control to render the HTML and call the Browser control's "Print" method to print the rendered page. Here a small example:

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    
    namespace WindowsFormsApplication3
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void btn_Load_Click(object sender, EventArgs e)
            {
                webBrowser1.Navigate(txt_URL.Text);
            }
    
            private void btn_Home_Click(object sender, EventArgs e)
            {
                txt_URL.Text = "http://www.heesch.net"  ;
    btn_Load_Click(this, e); } private void btn_Print_Click(object sender, EventArgs e) { // Print preview ... // webBrowser1.ShowPrintPreviewDialog(); // direct print webBrowser1.Print(); } } }
    ;

     

    This Forms program will print the rendered HTML page to the default printer when you press the "Print" button ..

    Cheers,

    Stefan

     




    Friday, November 11, 2011 10:00 PM

All replies

  • Hi,

    You could use a Browser control to render the HTML and call the Browser control's "Print" method to print the rendered page. Here a small example:

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    
    namespace WindowsFormsApplication3
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void btn_Load_Click(object sender, EventArgs e)
            {
                webBrowser1.Navigate(txt_URL.Text);
            }
    
            private void btn_Home_Click(object sender, EventArgs e)
            {
                txt_URL.Text = "http://www.heesch.net"  ;
    btn_Load_Click(this, e); } private void btn_Print_Click(object sender, EventArgs e) { // Print preview ... // webBrowser1.ShowPrintPreviewDialog(); // direct print webBrowser1.Print(); } } }
    ;

     

    This Forms program will print the rendered HTML page to the default printer when you press the "Print" button ..

    Cheers,

    Stefan

     




    Friday, November 11, 2011 10:00 PM
  • Hi R.odney,

    Stefan's suggestion looks good.

    We have not heard from you in a couple of days.

    Please post back at your convenience if we can assist further.

    Enjoy your day!


    Min Zhu [MSFT]
    MSDN Community Support | Feedback to us
    Tuesday, November 15, 2011 1:16 AM
    Moderator