导出为pdf时出现特殊字符的问题 [英] Problem in a special characters when exporting as pdf
本文介绍了导出为pdf时出现特殊字符的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
每个人
我想将页面或gridview导出为pdf,但我在删除或隐藏特殊字符时遇到问题。
当我以PDF格式输出时,如何使用utf8的问题&当我导出到word或excel时,我解决了同样的问题
wor& excel代码:
Response.Clear()
Response.Buffer = True
Response.Write( < meta http-equiv =Content-Type content =text / xhtml + xml; charset = UTF-8/>)
Response.AddHeader( Content-Disposition, attachment; filename = All报告List.xls)
Response.ContentType = application / vnd.ms-excel
Response.Charset = UTF-8
Response.BinaryWrite(System.Text.Encoding.UTF8.GetPreamble)
Dim writer As < span class =code-keyword>新 System.IO.StringWriter()
Dim html As 新 System.Web.UI .HtmlTextWriter(writer)
gv_reports.RenderControl(html)
Response.Write(writer)
Response。 End ()
这个pdf代码我改了1000多次但不行:
gv_reports.HeaderStyle.ForeColor = Drawing.Color.Black
gv_reports.HeaderRow.Style.Add( width, 15%)
Response.ContentType = application / pdf
Response.AddHeader( content-disposition, att achment; filename =所有报告List.pdf)
Response.Write( String .Format( < meta http-equiv = Content-Type content = text / xhtml + xml; charset = UTF-8 />,编码。 UTF8.HeaderName))
' Response.Write(< meta http-equiv =Content-输入content =text / xhtml + xml; charset = UTF-8/>)
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Dim sw 作为 新 StringWriter()
Dim hw 作为 新 HtmlTextWriter(sw)
gv_reports.RenderControl(hw)
' Me.Page.RenderControl(hw)
Dim sr As 新 StringReader(sw.ToString())
Dim pdfDoc 作为 新文档(PageSize。 A3.Rotate, 10 .0F, 10 .0F, 10 跨度> .0F , 0 .0F)
Dim htmlparser As 新 simpleparser.HTMLWorker(pdfDoc)
PdfWriter.GetInstance(pdfDoc,Response.OutputStream)
pdfDoc.Open()
pdfDoc.Add(新 iTextSharp.text.Paragraph( 所有报告)) 添加标题
pdfDoc.Add( 新 iTextSharp.text.Phrase(Environment.NewLine))' Add NewLine
htmlparser.Parse(sr)
pdfDoc.Close()
Response.Write(pdfDoc)
Response。结束()
谢谢
解决方案
您必须在web.config中添加这些行:
< 配置 >
< system.web >
< 全球化 >
fileEncoding =utf-8
requestEncoding =utf-8
responseEncoding =utf-8
culture =en-US
uiCulture =en -US
/>
< /全球化 > < / system.web >
< / configuration >
快乐出口!
它不起作用。
换句话说,我有阿拉伯语字母,但不会出现。
Christin感谢您的帮助
Hi every one
I want to export page or gridview as pdf but I have a problem in a special characters they are removed or hidden.
The probel in how to use utf8 when I export as pdf & I solved the same probelm when I export to word or excel
wor & excel code:
Response.Clear()
Response.Buffer = True
Response.Write("<meta http-equiv=""Content-Type"" content=""text/xhtml+xml; charset=UTF-8"" />")
Response.AddHeader("Content-Disposition", "attachment; filename=All Reports List.xls")
Response.ContentType = "application/vnd.ms-excel"
Response.Charset = "UTF-8"
Response.BinaryWrite(System.Text.Encoding.UTF8.GetPreamble)
Dim writer As New System.IO.StringWriter()
Dim html As New System.Web.UI.HtmlTextWriter(writer)
gv_reports.RenderControl(html)
Response.Write(writer)
Response.End()
And this pdf code I changed it more than 1000 time but not work:
gv_reports.HeaderStyle.ForeColor = Drawing.Color.Black
gv_reports.HeaderRow.Style.Add("width", "15%")
Response.ContentType = "application/pdf"
Response.AddHeader("content-disposition", "attachment;filename=All Reports List.pdf")
Response.Write(String.Format("<meta http-equiv=Content-Type content=text/xhtml+xml;charset=UTF-8/>", Encoding.UTF8.HeaderName))
'Response.Write("<meta http-equiv=""Content-Type"" content=""text/xhtml+xml; charset=UTF-8"" />")
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Dim sw As New StringWriter()
Dim hw As New HtmlTextWriter(sw)
gv_reports.RenderControl(hw)
' Me.Page.RenderControl(hw)
Dim sr As New StringReader(sw.ToString())
Dim pdfDoc As New Document(PageSize.A3.Rotate, 10.0F, 10.0F, 10.0F, 0.0F)
Dim htmlparser As New simpleparser.HTMLWorker(pdfDoc)
PdfWriter.GetInstance(pdfDoc, Response.OutputStream)
pdfDoc.Open()
pdfDoc.Add(New iTextSharp.text.Paragraph("All Reports")) 'Add Header
pdfDoc.Add(New iTextSharp.text.Phrase(Environment.NewLine)) 'Add NewLine
htmlparser.Parse(sr)
pdfDoc.Close()
Response.Write(pdfDoc)
Response.End()
Thank you
解决方案
You must add these lines in your web.config:
<configuration> <system.web> <globalization> fileEncoding="utf-8" requestEncoding="utf-8" responseEncoding="utf-8" culture="en-US" uiCulture="en-US" /> </globalization></system.web> </configuration>
Happy exporting!
It doesn`t work.
In other word I have arabic letters that doesn`t appear.
Christin thank you for your help
这篇关于导出为pdf时出现特殊字符的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文