Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
LitCompleteDetails.Text = CompleteDetails();
        Response.Clear(); //this clears the Response of any headers or previous output
        Response.Buffer = true; //ma
        Response.ContentType = "application/pdf";
        Response.AddHeader("content-disposition", "attachment;filename=Transport.pdf");
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        StringWriter sw = new StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(sw);
        LitCompleteDetails.RenderControl(hw);

        StringReader sr = new StringReader(sw.ToString());
        Document pdfDoc = new Document();
        HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
        PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
        pdfDoc.Open();
        htmlparser.Parse(sr);
        pdfDoc.Close();
        Response.Write(pdfDoc);
        Response.End();
Posted

1 solution

Step1:

In this Step, you need to download .ttf file for Arabic language. Here is the link:

Download Traditional Arabic Font - Cool Text[^]

Step2:

In this step you need to load the .ttf(which one you downloaded) and write the text to Pdfobject.
C#
BaseFont bf = BaseFont.CreateFont(Environment.GetEnvironmentVariable("windir") + @"\fonts\ArialUni.TTF", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);

PdfPTable table = new PdfPTable(GridView1.Columns.Count);

//Set Font and Font Color
Font font = new Font(bf, 10, Font.NORMAL);
font.Color = new Color(GridView1.HeaderStyle.ForeColor);
PdfPCell cell = new PdfPCell(new Phrase(12, "Arabic Text", font));

//Set Header Row BackGround Color
cell.BackgroundColor = new Color(GridView1.HeaderStyle.BackColor);
table.AddCell(cell);

Follow below link that might help you:

Export GridView to PDF using iTextSharp with different language characters[^]
 
Share this answer
 
Comments
Member 9994001 27-Dec-15 2:01am    
Mr. Manas, i m not using Gridview, first i am writing a function public string CompleteDetails(), then i am converting that into Literal.text.
[no name] 27-Dec-15 2:32am    
It is correct that you are not using Gridview. However you can follow the code which is provided for Label's text. Use ttf file and load into PDFInstance object.
Ashutosh shukla207 27-Dec-15 8:43am    
whatever manas had said .. thats applicable if u take the grid runtime . and bind it ...you can use .net executables for this . download .dll kit . its available for Excel and pdf both.

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