Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET PDF Unicode
Hi there ! i got a problem with my project about Unicode char ! plzz help me !
HtmlForm form = new HtmlForm();
        string imagepath = Server.MapPath("img");
        form.Controls.Add(GroupingGridView1);
        StringWriter sw = new StringWriter();
        Response.ContentEncoding = System.Text.Encoding.UTF8;
 
        HtmlTextWriter hTextWriter = new HtmlTextWriter(sw);
        form.Controls[0].RenderControl(hTextWriter);
        string html = HttpUtility.HtmlDecode(sw.ToString());
        string pathHTML = "c:\\test.html";
        StreamWriter filehtml = new System.IO.StreamWriter(pathHTML);
        filehtml.Write(html);
        filehtml.Dispose();
        Document Doc = new Document(PageSize.A4);
        
        string Path = Environment.GetFolderPath
        (Environment.SpecialFolder.Desktop)
        + "\\baocao.pdf";
        PdfWriter.GetInstance
        (Doc, new FileStream(Path, FileMode.Create));
        Doc.Open();
 
        iTextSharp.text.Image clogo = iTextSharp.text.Image.GetInstance(imagepath + "/slogo.jpg");
        clogo.Alignment = iTextSharp.text.Image.ALIGN_LEFT;
        BaseFont bf = BaseFont.CreateFont(@"C:\WINDOWS\Fonts\TIMES.TTF", BaseFont.IDENTITY_H, true);
        iTextSharp.text.Font fonttitle = new iTextSharp.text.Font(bf, 15);
        iTextSharp.text.Font font = new iTextSharp.text.Font(bf, 10);
        iTextSharp.text.Font fonttext = new iTextSharp.text.Font(bf, 12);
 

        Paragraph header = new Paragraph();
        header.Alignment = Element.ALIGN_CENTER;
        Paragraph text = new Paragraph();
 
        Chunk c1 = new Chunk("Báo cáo thống kê thiết bị \n", fonttitle);
        Chunk c2 = new Chunk(DateTime.Now.ToShortDateString() + "\n\n", font);
        header.Add(c1);
        header.Add(c2);
        Doc.Add(clogo);
        Doc.Add(header);
        List<IElement> objects;
        var stream = new StreamReader(pathHTML, Encoding.UTF8);//.ReadToEnd();
        
        objects = iTextSharp.text.html.simpleparser.HTMLWorker.ParseToList(stream, new StyleSheet());
        Doc.NewPage();
        for (int k = 0; k < objects.Count; k++)
        {
            PdfPTable table = new PdfPTable(1);
 
            table.RunDirection = PdfWriter.RUN_DIRECTION_RTL;
            var els = (IElement)objects[k];
            //i can not add UNICODE when I ADD to DOCUMENT
            Doc.Add((IElement)objects[k]);           
        }  
            stream.Dispose();
            Doc.Close();
 
        Response.ClearContent();
        Response.ClearHeaders();
        Response.ContentType = "application/pdf";
        Response.AddHeader
        ("Content-Disposition", "attachment; filename=" + strS);
        Response.TransmitFile(strS);
        Response.End();
        //Response.WriteFile(strS);
        Response.Flush();
        Response.Clear();
Posted 25-Oct-11 21:41pm
Edited 25-Oct-11 21:52pm
RaisKazi33.1K
v2
Comments
Richard MacCutchan at 26-Oct-11 7:44am
   
What problem? Please explain which part of your code is not working and why.
Marc A. Brown at 26-Oct-11 9:42am
   
You have a comment in your code saying that you cannot add unicode when you add to document; however, you haven't said what happens. Exception? The content just doesn't show up? Computer explodes? Cats and dogs live in sin? Seriously, you need to specify what exactly goes wrong since it's unlikely that someone is going to take the time to create a test project to run your code in.
Hua Trung at 26-Oct-11 23:13pm
   
hi Marc A. Brown and Richard MacCutchan ! it creat a pdf not exception ! my font in pdf is broken at some chars like 'ộ' 'ế' ..etc.. !
in my CODE this line:
Chunk c1 = new Chunk("Báo cáo thống kê thiết bị \n", fonttitle);
it show right format ! and it not broken. i can not add a pdftable (unicode format) to my documentlike this CODE:
for (int k = 0; k < objects.Count; k++)
{
PdfPTable table = new PdfPTable(1);

table.RunDirection = PdfWriter.RUN_DIRECTION_RTL;
var els = (IElement)objects[k];
//i can not add UNICODE when I ADD to DOCUMENT
Doc.Add((IElement)objects[k]);
}
 
plzzz help me ! thanx for reply !

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
Comments
Hua Trung at 27-Oct-11 5:07am
   
Dear Mehdi Gholam ! i know to add font with a Paragraph , Pharase, but i dun know how to add font with a IElement - PdfPTable, when i debuged my code, i saw my stream variable,it contain unicode, and when i convert to a PdfPTable (i dun know how to access row value- and my pdf it not contain a UNICODE CHARS , could u help me plz ! :((

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

  Print Answers RSS
0 Mathew Soji 274
1 BillWoodruff 270
2 Afzaal Ahmad Zeeshan 244
3 Sergey Alexandrovich Kryukov 240
4 Raul Iloc 160
0 OriginalGriff 6,219
1 Sergey Alexandrovich Kryukov 5,853
2 DamithSL 5,103
3 Manas Bhardwaj 4,549
4 Maciej Los 3,845


Advertise | Privacy | Mobile
Web04 | 2.8.1411019.1 | Last Updated 27 Oct 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100