'Print HTML'에 해당되는 글 1건
2007/08/28 08:08
Print HTML In C# With Or Without The Web Browser Control And The Print Dialog
2007/08/28 08:08 in C#

<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 theHtmlPrinter 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();
hpObjPrintHtml(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>
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 theHtmlPrinter 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();
hpObjPrintHtml(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>
Prev

Rss Feed