ABCpdf 5编码问题(特殊字符)

sl3*_*dg3 1 c# asp.net abcpdf

我正在使用ABCpdf第5版,以便将一些html页面呈现为PDF.

我基本上使用HttpServerUtility.Execute()- 方法来检索pdf的html:

System.IO.StringWriter writer = new System.IO.StringWriter();
server.Execute(requestUrl, writer);
string pageResult = writer.ToString();

WebSupergoo.ABCpdf5.Doc pdfDoc = new WebSupergoo.ABCpdf5.Doc();
pdfDoc.AddImageHtml(pageResult);

response.Buffer = false;
response.ContentType = "application/pdf";
response.AddHeader("Content-Disposition", "attachment;filename=MyPdf_" + 
    FormatDate(DateTime.Now, "yyyy-MM-dd") + ".pdf");
response.BinaryWrite(pdfDoc.GetData());
Run Code Online (Sandbox Code Playgroud)

现在有些像Umlaute(AOU)特殊字符替换为空的空间.有趣的是并非全部.我弄清楚了:在html页面中我有.

`<meta http-equiv="content-type" content="text/xhtml; charset=utf-8" />` 
Run Code Online (Sandbox Code Playgroud)

如果我解析它,所有特殊字符都会正确呈现.但在我看来,这似乎是一个丑陋的黑客.

在早些时候我没有使用HttpServerUtility.Execute(),但我让ABCpdf调用URL本身:pdfDoc.AddImageUrl("someUrl");.我没有这样的编码问题.

我还能尝试什么?

dev*_*vio 5

刚刚遇到ABCpdf 8的这个问题.

在您的代码中,您检索HTML内容并将pageResult传递给AddImageHtml().正如文档所述,

ABCpdf将此HTML保存到临时文件中,并使用"file://"协议说明符呈现文件.

没有提到的是临时文件是UTF-8编码的,但HTML文件中没有说明编码.

<meta>标签实际上设置了所需的编码,并解决了我的问题.

避免声明编码的一种方法是使用我希望从HTTP/HTML响应中检测HTML编码的AddImageUrl()方法.