0

我正在开发窗口应用程序。我在使用 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。

4

1 回答 1

0

您需要加载 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);
        }
于 2018-04-29T06:45:31.223 回答