I'm trying to create a content page with lines like:

Chapter one...................101
Chapter two...................102
etc.

Some chapters are in English some are in Arabic. But the page numbers should
always be on one side (left or right).

I have this 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("C:\\sample.pdf", FileMode.Create));
                doc.Open();
                doc.SetMargins(52f, 52f, 52f, 52f);
                PdfContentByte content = writer.DirectContent;
                content.SaveState();
                content.Rectangle(doc.Left, 0, doc.Right - doc.Left,
doc.Top);
                content.SetColorFill(new BaseColor(240, 240, 240));
                content.Fill();
                content.RestoreState();
                ColumnText colt = new ColumnText(content);
                colt.SetSimpleColumn(doc.Left, doc.Bottom, doc.Right,
doc.Top);
                ColumnText coltrtl = new ColumnText(content);
                coltrtl.SetSimpleColumn(doc.Left, doc.Bottom, doc.Right,
doc.Top);
                coltrtl.RunDirection = *PdfWriter.RUN_DIRECTION_RTL*;

                Paragraph par = new Paragraph("مكتبة مؤلفة من 15 دورة
تفاعلية", font);
                par.Alignment = *Element.ALIGN_LEFT*;
                coltrtl.AddElement(par);
                coltrtl.Go();

                doc.Close();
            }/

As you can see, the /Element.ALIGN_LEFT/ for RTL ColumnText means aligning
to the right:
<http://itext-general.2136553.n4.nabble.com/file/n4660411/02.png> 

Now let's add a separator:

                /Paragraph par = new Paragraph("مكتبة مؤلفة من 15 دورة
تفاعلية", font);
                par.Alignment = Element.ALIGN_LEFT;
                *iTextSharp.text.pdf.draw.DottedLineSeparator separator =
new iTextSharp.text.pdf.draw.DottedLineSeparator();
                par.Add(new Chunk(separator));
                par.Add(new Chunk("123", font));
*                coltrtl.AddElement(par);
                coltrtl.Go();/

We get:
<http://itext-general.2136553.n4.nabble.com/file/n4660411/03.png> 

When the separator is added we have to align the paragraph to the right:

                /Paragraph par = new Paragraph("مكتبة مؤلفة من 15 دورة
تفاعلية", font);
                par.Alignment = *Element.ALIGN_RIGHT*;
                iTextSharp.text.pdf.draw.DottedLineSeparator separator = new
iTextSharp.text.pdf.draw.DottedLineSeparator();
                par.Add(new Chunk(separator));
                par.Add(new Chunk("123", font));
                coltrtl.AddElement(par);
                coltrtl.Go();/

<http://itext-general.2136553.n4.nabble.com/file/n4660411/04.png> 

This looks good. But some Arabic text may contain English words:

                /Paragraph par = new Paragraph("*MS Office 2013 - الترقية من
MS Office 2010*", font);
                par.Alignment = Element.ALIGN_RIGHT;
                iTextSharp.text.pdf.draw.DottedLineSeparator separator = new
iTextSharp.text.pdf.draw.DottedLineSeparator();
                par.Add(new Chunk(separator));
                par.Add(new Chunk("123", font));
                coltrtl.AddElement(par);
                coltrtl.Go();/

<http://itext-general.2136553.n4.nabble.com/file/n4660411/05.png> 

To fix this we have to add the RightToLeft mark at the end of the string:

                /Paragraph par = new Paragraph("MS Office 2013 - الترقية من
MS Office 2010" *+ ((char)0x200F)*, font);
                par.Alignment = Element.ALIGN_RIGHT;
                iTextSharp.text.pdf.draw.DottedLineSeparator separator = new
iTextSharp.text.pdf.draw.DottedLineSeparator();
                par.Add(new Chunk(separator));
                par.Add(new Chunk("123", font));
                coltrtl.AddElement(par);
                coltrtl.Go();/

<http://itext-general.2136553.n4.nabble.com/file/n4660411/06.png> 

This looks good. Now we have to solve a situation for multi-line chapter
names:

                Paragraph par = new Paragraph("*تفاعليةتفاعليةتفاعلية
تفاعليةتفاعليةتفاعلية تفاعليةتفاعليةتفاعلية تفاعليةتفاعليةتفاعلية*" +
((char)0x200F), font);
                par.Alignment = Element.ALIGN_RIGHT;
                iTextSharp.text.pdf.draw.DottedLineSeparator separator = new
iTextSharp.text.pdf.draw.DottedLineSeparator();
                par.Add(new Chunk(separator));
                par.Add(new Chunk("123", font));
                coltrtl.AddElement(par);
                coltrtl.Go();

<http://itext-general.2136553.n4.nabble.com/file/n4660411/07.png> 

And we have a problem. The first line should be aligned to the right. But as
we know, we cannot use Element.ALIGN_LEFT:

                Paragraph par = new Paragraph("تفاعليةتفاعليةتفاعلية
تفاعليةتفاعليةتفاعلية تفاعليةتفاعليةتفاعلية تفاعليةتفاعليةتفاعلية" +
((char)0x200F), font);
                par.Alignment = *Element.ALIGN_LEFT*;
                iTextSharp.text.pdf.draw.DottedLineSeparator separator = new
iTextSharp.text.pdf.draw.DottedLineSeparator();
                par.Add(new Chunk(separator));
                par.Add(new Chunk("123", font));
                coltrtl.AddElement(par);
                coltrtl.Go();

<http://itext-general.2136553.n4.nabble.com/file/n4660411/08.png> 

Can this be solved?

Sometimes, we need to keep the page numbers on the right side even for
Arabic texts. I see only one solution: Add the page number first then the
chapter title:

                /Paragraph par = *new Paragraph("123", font);*
                par.Alignment = Element.ALIGN_RIGHT;
                iTextSharp.text.pdf.draw.DottedLineSeparator separator = new
iTextSharp.text.pdf.draw.DottedLineSeparator();
                par.Add(new Chunk(separator));
                *par.Add(new Chunk("مكتبة مؤلفة من 15 دورة تفاعلية" +
((char)0x200F), font));
*                coltrtl.AddElement(par);
                coltrtl.Go();/

<http://itext-general.2136553.n4.nabble.com/file/n4660411/09.png> 

This works but only for single-line chapters:

                /Paragraph par = new Paragraph("123", font);
                par.Alignment = Element.ALIGN_RIGHT;
                iTextSharp.text.pdf.draw.DottedLineSeparator separator = new
iTextSharp.text.pdf.draw.DottedLineSeparator();
                par.Add(new Chunk(separator));
                par.Add(new Chunk(*"تفاعليةتفاعليةتفاعلية
تفاعليةتفاعليةتفاعلية تفاعليةتفاعليةتفاعلية تفاعليةتفاعليةتفاعلية"* +
((char)0x200F), font));
                coltrtl.AddElement(par);
                coltrtl.Go();/

<http://itext-general.2136553.n4.nabble.com/file/n4660411/10.png> 

Can this be solved?

Similar problem is with English text. I'm unable to draw a multi-line
chapter name and a page number on the left side:

                /Paragraph par = new Paragraph(*"This is a chapter with a
really really really really really really really long name"*, font);
                par.Alignment = Element.ALIGN_RIGHT;
                iTextSharp.text.pdf.draw.DottedLineSeparator separator = new
iTextSharp.text.pdf.draw.DottedLineSeparator();
                *separator.Alignment = Element.ALIGN_RIGHT;
*                par.Add(new Chunk(separator));
                par.Add(new Chunk("123", font));
                coltrtl.AddElement(par);
                coltrtl.Go();/

<http://itext-general.2136553.n4.nabble.com/file/n4660411/11.png> 

The /separator.Alignment /has no effect. We can use the same trick with the
RightToLeft mark:

                /Paragraph par = new Paragraph("This is a chapter with a
really really really really really really really long name" +
*((char)0x200F*), font);
                par.Alignment = Element.ALIGN_RIGHT;
                iTextSharp.text.pdf.draw.DottedLineSeparator separator = new
iTextSharp.text.pdf.draw.DottedLineSeparator();
                separator.Alignment = Element.ALIGN_RIGHT;
                par.Add(new Chunk(separator));
                par.Add(new Chunk("123", font));
                coltrtl.AddElement(par);
                coltrtl.Go();/

<http://itext-general.2136553.n4.nabble.com/file/n4660411/12.png> 

But we have the same problem - the first line should be aligned to the
right.




--
View this message in context: 
http://itext-general.2136553.n4.nabble.com/The-story-about-English-Arabic-and-a-dotted-separator-tp4660411.html
Sent from the iText - General mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer
Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports
Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper
Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer
http://pubads.g.doubleclick.net/gampad/clk?id=154622311&iu=/4140/ostg.clktrk
_______________________________________________
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