如何使用TxtextControl打印HTML



我在窗口应用程序上工作。我面临着使用TXTEXTCONTROL打印网页或HTML的问题。我需要做的是将html传递到方法,它将打印。

public void PrintHtml(string html)
{ 
 PrintDocument pd = new PrintDocument();
            pd.PrinterSettings = new PrinterSettings();
            pd.PrinterSettings.PrinterName = printerName;
            textControl1.Text =html;
            pd.PrinterSettings.PrintFileName = "d:\abc.pdf";
            pd.DefaultPageSettings.PaperSize = new PaperSize("Label", (int)textControl1.PageSize.Width, (int)textControl1.PageSize.Height);
            pd.DefaultPageSettings.Margins = new Margins((int)textControl1.PageMargins.Left, (int)textControl1.PageMargins.Right, (int)textControl1.PageMargins.Top, (int)textControl1.PageMargins.Bottom);
  pd.DefaultPageSettings.Landscape = false;
 textControl1.Print(pd);
    }

任何人,请指导我,如何打印html。

您需要加载html才能打印您的HTML页面。

    public void PrintHtml(string html)
    { 
textControl1.Load("your file path",StringStreamType.HTMLFormat)
     PrintDocument pd = new PrintDocument();
                pd.PrinterSettings = new PrinterSettings();
                pd.PrinterSettings.PrinterName = printerName;
                textControl1.Text =html;// this line not needed.
                pd.PrinterSettings.PrintFileName = "d:\abc.pdf";
                pd.DefaultPageSettings.PaperSize = new PaperSize("Label", (int)textControl1.PageSize.Width, (int)textControl1.PageSize.Height);
                pd.DefaultPageSettings.Margins = new Margins((int)textControl1.PageMargins.Left, (int)textControl1.PageMargins.Right, (int)textControl1.PageMargins.Top, (int)textControl1.PageMargins.Bottom);
      pd.DefaultPageSettings.Landscape = false;
     textControl1.Print(pd);
        }

相关内容

  • 没有找到相关文章

最新更新