Search results for 'PrintHtml'. 1 post(s) found.

  1. 2007/08/28 Print HTML In C# With Or Without The Web Browser Control And The Print Dialog
2007/08/28 08:08

Print HTML In C# With Or Without The Web Browser Control And The Print Dialog


Printing with the web browser control in .NET platform is not hard work. But the challenge for me was to navigate to a specific URL and then Print the document with a single click event. There was another challenge I had to face,when I tried to Print an HTML document from its source in the same manner. Well,this article describes some techniques to Print an HTML document with that challenge (if anyone thinks so). This code is also able to Print an HTML page without the Print dialog. So,if any one needs Printing without any user interaction,this code may be helpful for you. In addition,this code is also able to Print an HTML document without any web browser control in the form.

<PRE lang=cs nd="7">
object em =null;
axW.ExecWB(
  SHDocVw.OLECMDID.OLECMDID_Print,
  SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_PROMPTUSER,
  ref em,ref em);
</PRE>
<P nd="11">For Printing without Print dialog:</P><PRE lang=cs nd="12">
axW.ExecWB(
  SHDocVw.OLECMDID.OLECMDID_Print,
  SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER,
  ref em,ref em);
</PRE>
<P nd="15">Now,what if you want to navigate and Print with a single click? You
have to navigate the web browser to a specific URL with its <CODE
nd="16">Navigate</CODE> method and wait until it loads the whole HTML page. That
is:</P><PRE lang=cs nd="18">
for(;axW.ReadyState!=SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE;)

{
    System.Windows.Forms.Application.DoEvents();
}</PRE>
<P nd="19">Then Print the page with any of the previous options you want.</P>
<P nd="20">Now,if you want to Print an HTML page from its source,what should
do is,just add the HtmlPrinter project to your solution. Then go to Add
References option,by right clicking on your own project. From the Project tab,select the HtmlPrinter project.</P>
<P nd="21">Now,to Print directly,you need to create a <CODE
nd="22">HtmlPrinter</CODE> object and then call its <CODE
nd="23">PrintUrlFromMemory</CODE> method with the URL as its parameter.</P><PRE lang=cs nd="25">
using HtmlPrinter;


hpObj=new HtmlPrinter.HtmlPrinter();
hpObj.PrintUrlFromMemory(txtUrl.Text);</PRE>
<P nd="27">Now,you add the code in your project to Print the HTML page from its
source text:</P><PRE lang=cs nd="28">
HtmlPrinter.HtmlPrinter hpObj=new HtmlPrinter.HtmlPrinter();
hpObj.PrintHtml(txtString.Text,true);</PRE>
<P nd="31">If you want to Print without the Print dialog,then use the following
line:</P><PRE lang=cs nd="32">hpObj.PrintHtml(txtString.Text,false);</PRE>

Trackback 4 Comment 0

Trackback : Cannot send a trackbact to this post.

  1. Subject Cheap phentermine.

    Tracked from Cheap phentermine without prescription. 2010/01/25 17:56 delete

    Cheap phentermine. Cheap phentermine no prescription. Phentermine cheap. Buy cheap phentermine online. Buy phentermine order cheap online.

  2. Subject different money making ideas

    Tracked from moneyideas 2010/01/29 04:16 delete

    moneyideas

  3. Subject different money making ideas

    Tracked from moneyideas 2010/01/29 12:56 delete

    moneyideas

  4. Subject different money making ideas

    Tracked from moneyideas 2010/01/31 16:44 delete

    moneyideas