Hi..

 

I try this code but still cannot change font from Helevetica to my font. I see 
at properties of PDF file. Do you have any sample or suggestion for coding below

 

   

public class MyFontFactoryImpl : FontFactoryImp

    {

        Font defaultFont;

        public MyFontFactoryImpl()

        {

 

            BaseFont tahoma = 
BaseFont.CreateFont(@"C:\WINDOWS\Fonts\tahoma.ttf", BaseFont.IDENTITY_H, 
BaseFont.NOT_EMBEDDED);

            defaultFont = new Font(tahoma, 12);

           

        }

        public override Font GetFont(string fontname, string encoding)

        {

            return defaultFont;

        }

    }

 

    public class HtmlToPdf

    {

        string _html;

        public HtmlToPdf(string html)

        {

            if (!(FontFactory.FontImp is MyFontFactoryImpl))

                FontFactory.FontImp = new MyFontFactoryImpl();

            _html = html;

        }

 

        public void Render(Stream stream)

        {

            StringReader sr = new StringReader(_html);

            Document pdfDoc = new Document();

            PdfWriter.GetInstance(pdfDoc, stream);

            HTMLWorker htmlparser = new HTMLWorker(pdfDoc);

            pdfDoc.Open();

            htmlparser.Parse(sr);

            pdfDoc.Close();

        }

 

        public void Render(HttpResponse response, string fileName)

        {

            response.Clear();

            response.AddHeader("Content-Disposition", 
string.Format("attachment; filename={0}", fileName));

            response.ContentType = "application/octet-stream";

 

            Render(response.OutputStream);

 

            response.End();

        }

    }

 

  protected void ImageButton2_Click(object sender, ImageClickEventArgs e)

    {

        StringBuilder sb = new StringBuilder();

        sb.Append("Test");  ß Can see in PDF file

sb.Append("ทดสอบ"); ß Can not see in PDF file for Thai

 

        HtmlToPdf htmlToPdf = new HtmlToPdf(sb.ToString());

 

        htmlToPdf.Render(Response, "test.pdf");

 

    }

 

Thank you for your help

 

Nattapong S.

 

From: 1T3XT BVBA [mailto:[email protected]] 
Sent: Wednesday, January 05, 2011 4:51 PM
To: [email protected]
Subject: Re: [iText-questions] C# iTextSharp: Export PDF from GridView can not 
display in Thai language

 

Op 5/01/2011 8:53, Nattapong Suwannatrai schreef: 

        htmlworker.Parse(sr);  ß Can Not Display In Thai Language when pulled 
data from gridview to write down pdf.

Not sure what you mean by gridview, but if you want to use a different font 
than Helvetica in HtmlWorker, you need to define a FontProvider as explained on 
page 310 of the Second Edition of iText in Action. You also have to make sure 
the HTML is read using the proper encoding.



 I think the default front of iTextsharp is HELVETICA. It can support Thai 
language.

The default font is Helvetica and it doesn't support Thai. 




Can I add defined font in  "htmlparser.Parse(sr)" ? 

You need to define a FontProvider as documented in the book.

You also need to SUBSCRIBE to the mailing list if you want to post/receive 
further questions and answers.
Further questions that are kept on hold will be DELETED.

------------------------------------------------------------------------------
Learn how Oracle Real Application Clusters (RAC) One Node allows customers
to consolidate database storage, standardize their database environment, and, 
should the need arise, upgrade to a full multi-node Oracle RAC database 
without downtime or disruption
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Many questions posted to this list can (and will) be answered with a reference 
to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: 
http://itextpdf.com/themes/keywords.php

Reply via email to