Re: Chunk.GetWidthPoint() returns wrong width

vadamovsky <[email protected]>
Newsgroups gmane.comp.java.lib.itext.general
Message-ID <[email protected]>
I forgot to note that I'm using iTextSharp v5.5.2.

Sample file:
<http://itext-general.2136553.n4.nabble.com/file/n4660296/sample.png> 

The file can be downloaded here:
https://mega.co.nz/#!rlBzXDoS!ZQ1F6Z0IVxgeNXrnX8a3cVAyJ1Xk4aPGYH3tuvIV8fI

The code:

           
FontFactory.RegisterDirectory(Environment.GetFolderPath(Environment.SpecialFolder.Fonts));
            iTextSharp.text.Font font = FontFactory.GetFont("Tahoma",
BaseFont.IDENTITY_H, 15f, iTextSharp.text.Font.NORMAL, new BaseColor(0, 0,
0));
            using (Document doc = new Document(PageSize.A4))
            {
                PdfWriter writer = PdfWriter.GetInstance(doc, new
FileStream("sample.pdf", FileMode.Create));
                doc.Open();
                doc.SetMargins(52f, 52f, 52f, 52f);
                PdfContentByte content = writer.DirectContent;
                ColumnText colt = new ColumnText(content);

                float y = 50;
                colt.SetSimpleColumn(doc.Left, doc.Bottom, doc.Right,
doc.Top - y);
                colt.AddElement(new Paragraph("English text, standard
spacing"));
                Chunk ch = new Chunk("My sample text line", font);
                float chunkWidth = ch.GetWidthPoint();
                content.SaveState();
                content.Rectangle(doc.Left, doc.Top - y - 45, chunkWidth,
20);
                content.SetColorFill(BaseColor.LIGHT_GRAY);
                content.Fill();
                content.RestoreState();
                colt.AddElement(ch);
                colt.Go();

                y = 100;
                colt.SetSimpleColumn(doc.Left, doc.Bottom, doc.Right,
doc.Top - y);
                colt.AddElement(new Paragraph("English text, spacing 1"));
                colt.Go();
                content.SetCharacterSpacing(1);
                ch = new Chunk("My sample text line", font);
                chunkWidth = ch.GetWidthPoint();
                content.SaveState();
                content.Rectangle(doc.Left, doc.Top - y - 45, chunkWidth,
20);
                content.SetColorFill(BaseColor.LIGHT_GRAY);
                content.Fill();
                content.RestoreState();
                colt.AddElement(ch);
                colt.Go();

                y = 150;
                content.SetCharacterSpacing(0);
                colt.SetSimpleColumn(doc.Left, doc.Bottom, doc.Right,
doc.Top - y);
                colt.AddElement(new Paragraph("Arabic text, standard
spacing"));
                colt.RunDirection = PdfWriter.RUN_DIRECTION_RTL;
                ch = new Chunk("بلدي عينة خط النص", font);
                chunkWidth = ch.GetWidthPoint();
                content.SaveState();
                content.Rectangle(doc.Left, doc.Top - y - 45, chunkWidth,
20);
                content.SetColorFill(BaseColor.LIGHT_GRAY);
                content.Fill();
                content.RestoreState();
                colt.AddElement(ch);
                colt.Go();

                doc.Close();
            }



--
View this message in context: http://itext-general.2136553.n4.nabble.com/Chunk-GetWidthPoint-returns-wrong-width-tp4660266p4660296.html
Sent from the iText - General mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Slashdot TV.  
Video for Nerds.  Stuff that matters.
http://tv.slashdot.org/
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

iText(R) is a registered trademark of 1T3XT BVBA.
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.