Printing an HTML string without creating an HTML file?

How do I print an HTML string so that all HTML tags are recognized and displayed correctly? I suppose it's possible to create an .HTML file and print it, but if there is a way to do this without creating additional files, I would be interested to know how to do it. Thank!

Application:

pd.PrintPage += new PrintPageEventHandler(PrintDocument_PrintPage);
pd.Print();

More code:

static private void PrintDocument_PrintPage(Object sender, PrintPageEventArgs e) {
    Font printFont = new Font("Courier New", 12);
    e.Graphics.DrawString("<b>Hello</b> world", printFont, Brushes.Black, 0, 0);
}

Printed Result:

<b>Hello</b> world
+3
source share
2 answers

The object Graphicsdoes not understand HTML, but DrawStringwill do the same as you, as you found out.

You will need to use the Graphics object in bold for Helloand non-bold for worldand remove the HTML markup.

, HTML (, HTML Agility Pack) HTML .

WebBrowser . ​​

+4
0

Source: https://habr.com/ru/post/1791293/


All Articles