I have a table with two cells. The first cell is left aligned and the
second cell is right aligned. I also want to change the character spacing
of the text. I have found that changing the character spacing breaks the
alignment so the right align text ends up outside the boundaries if the
table.

I have created some test code below and the link to the output PDF is in
this link

https://skydrive.live.com/redir?resid=1ECE2061CFF9124B!190&authkey=!ANcB0z_BN3N4UFo

Are there any alternatives or workarounds to getting the character spacing
working well with the right alignment?

        public void CharacterSpacingTest()
        {
            float margin = 50;

            using (var stream = new MemoryStream())
            {
                Document document = new Document();
                document.SetPageSize(new Rectangle(PageSize.A4.Width,
PageSize.A4.Height));
                document.SetMargins(margin, margin, 30f, 100f);

                PdfWriter writer = PdfWriter.GetInstance(document, stream);
                writer.CloseStream = false;

                document.Open();

                PdfPTable table = new PdfPTable(new float[] { 100 });
                table.TotalWidth = PageSize.A4.Width - margin - margin;
                table.WidthPercentage = 100f;
                table.LockedWidth = true;

                // Create a row that is right aligned
                PdfPCell cell1 = new PdfPCell();
                cell1.AddElement(new Paragraph("Hello World") { Alignment =
Element.ALIGN_RIGHT });
                cell1.BorderWidth = 1;
                table.AddCell(cell1);

                // Change the character spacing
                PdfContentByte cb = writer.DirectContent;
                cb.SetCharacterSpacing(1f);

                // Create a row that is left aligned
                PdfPCell cell2 = new PdfPCell();
                cell2.AddElement(new Paragraph("Hello World"));
                cell2.BorderWidth = 1;
                table.AddCell(cell2);

                document.Add(table);

                document.Close();

                Blobs.SaveToFile(Blobs.LoadFromStream(stream),
@"c:\Dev\test.pdf");
            }
        }
------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:

Build for Windows Store.

http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
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

Reply via email to