我正在做一些使用HTML的工作,我想打印(在纸上)这些HTML文件,实际上,该文件不存在,所有内容都保存在一个字符串中,所有文本在HTML,但我想打印,已经格式化......使用C#格式打印HTML页面
例如:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string HTML =
"<html>" +
"<head>" +
" <style type=\"text/css\">" +
" .title {" +
" color: blue;" +
" text-decoration: bold;" +
" text-size: 1em;" +
" }" +
" .author {" +
" color: gray;" +
" }" +
" </style>" +
"</head>" +
"<body>" +
" <p>" +
" <span class=\"title\">{0}</span>" +
" <span class=\"author\">{1}</span>" +
" </p>" +
"</body>" +
"</html>";
// Just a sample of what I whant to do...
// PseudoCode
//Render the HTML code
RenderHTML aa = new RenderHTML(string.Format(HTML, "Alexandre", "Bencz"));
aa.PrintDocumentInPaper();
}
}
}
我发现:http://msdn.microsoft.com/en-us/library/w290k23d.aspx
但是,我whant知道是否有另一种方法做这是更好的方法..?
看到这篇文章:http://stackoverflow.com/questions/2593147/html-agility-pack-make-code-look-neat。它建议使用HtmlTidy包装来完成所有格式化并打印。 –
我明白这可能只是一些示例代码,但我会建议在字符串的开头使用'@'运算符来表示它为字符串文字,这将允许您避免使用所有的拼接。那么,或者如果您要连接数据,请确保您使用的是“StringBuilder”。祝你好运! –