ABCpdf与编码5问题(特殊字符) [英] ABCpdf 5 Problems with encoding (special characters)

查看:793
本文介绍了ABCpdf与编码5问题(特殊字符)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用ABCpdf第5版为了渲染一些HTML的页面转换成PDF。

I am using ABCpdf Version 5 in order to render some html-pages into PDFs.

我基本上是用 HttpServerUtility.Execute() - 为了检索HTML为PDF方法:

I basically use HttpServerUtility.Execute() - Method in order to retrieve the html for the pdf:

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());

现在部分的像Umlaute(AOU)特殊字符用空白代替。有趣的是他们不是全部。我没搞清楚:
中的HT​​ML页我。

Now some special characters like Umlaute (äöü) are replaced with an empty space. Interestingly not all of them. What I did figure out: Within the html-page I have.

`<meta http-equiv="content-type" content="text/xhtml; charset=utf-8" />` 

如果我解析这个了,所有的特殊字符都正确呈现。但是,这在我看来,像一个丑陋的黑客攻击。

If I parse this away, all special chars are rendered correctly. But this seems to me like an ugly hack.

在以前我没有使用 HttpServerUtility.Execute(),但我让ABCpdf调用的URL本身: pdfDoc.AddImageUrl(someUrl ); 。在那里,我没有这样的编码-问题。

In earlier days I did not use HttpServerUtility.Execute(), but I let ABCpdf call the URL itself: pdfDoc.AddImageUrl("someUrl");. There I had no such encoding-problems.

我可以尝试别的吗?

推荐答案

刚刚过这样的问题来了的 ABCpdf 8

Just came across this problem with ABCpdf 8.

在您的code检索HTML内容和pageResult传递给AddImageHtml()。随着<一个href=\"http://websupergoo.com/helppdf5/default.html?page=source/5-object_reference/doc/1-methods/addimagehtml.htm\"相对=nofollow>文档状态,

In your code you retrieve HTML contents and pass the pageResult to AddImageHtml(). As the documentation states,

ABCpdf保存该HTML到一个临时文件,并呈现文件
  使用文件://。协议说明

ABCpdf saves this HTML into a temporary file and renders the file using a 'file://' protocol specifier.

什么没有提及的是,临时文件是UTF-8烯$ C $光盘,但该编码未在HTML文件中所述

What is not mentioned is that the temp file is UTF-8 encoded, but the encoding is not stated in the HTML file.

在&lt; meta>标签实际上是设置所需的编码,并解决我的问题。

The <meta> tag actually sets the required encoding, and solved my problem.

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

One way to avoid the declaration of the encoding is to use the AddImageUrl() method that I expect to detect the HTML encoding from the HTTP/HTML response.

这篇关于ABCpdf与编码5问题(特殊字符)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆