Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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:

VB
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:

VB
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
Posted

You must add these lines in your web.config:

XML
<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!
 
Share this answer
 
It doesn`t work.

In other word I have arabic letters that doesn`t appear.

Christin thank you for your help
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900