我从数据库生成HTML,然后将它发送到PrinceXML以转换为PDF。我用它来做到这一点的代码是:PrinceXML:“Input is not proper UTF-8”
string _htmlTemplate = @"<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Transitional//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd""><html lang=""en-GB"" xml:lang=""en-GB"" xmlns=""http://www.w3.org/1999/xhtml""><head><meta http-equiv=""Content-type"" content=""text/html;charset=UTF-8"" /><title>Generated PDF Contract</title></head><body>{0}</body></html>";
string _pgeContent = string.Format(_htmlTemplate, sb.ToString());
writer.Write(sb.ToString());
Byte[] arrBytes = UTF8Encoding.Default.GetBytes(_pgeContent);
Stream s = new MemoryStream(arrBytes);
Prince princeConverter = new Prince(ConfigurationManager.AppSettings["PrinceXMLInstallLoc"].ToString());
princeConverter.SetLog(ConfigurationManager.AppSettings["PrinceXMLLogLoc"]);
princeConverter.AddStyleSheet(Server.MapPath(ConfigurationManager.AppSettings["FormsDocGenCssLocl"]));
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/pdf";
Response.BufferOutput = true;
然而,转换失败,出现错误:
Input is not proper UTF-8, indicate encoding ! Bytes: 0xA0 0x77 0x65 0x62
我已经采取了生成的HTML并将其上传到W3C验证。它将标记验证为UTF-8编码的XHTML 1.0 Transitional,没有错误或警告。
我也通过一个精细的牙梳寻找无效字符的文件。到目前为止没有。
任何人都可以推荐别的东西我可以试试吗?
是的,按照错误消息的建议将流转换为UTF-8。 – 2010-11-17 12:06:03
@DarinDimitrov W3c验证程序将它解析为有效的UTF-8编码的XHTML意味着它*是* UTF-8吗?或者我错过了什么......? – 5arx 2010-11-17 12:18:18