how to force a justified alignment on a pdfpcell

to justify a text on a pdfpcell i know these commands

PdfPCell Example= new PdfPCell(new paragraph("Some text here",MyFont));//previous created font
Example.HorizontalAlignment = Element.ALIGN_JUSTIFIED;

but i have a hmtl string , and i need to decode, and im doing like this

string txt = "long html string text"
PdfPCell Example2= new PdfPCell();
List<IElement> sr = HTMLWorker.ParseToList(new StringReader(txt ), style);//style was previous created
foreach (IElement element in sr)
{
    Example2.AddElement(element);
}
Example2.SetLeading(0f, 1.5f);
Example2.Border = 0;
Example2.PaddingBottom = 20;
Table1.AddCell(Example2);//table declared previous

ok , until this point all is working and my pdfp document is fine but i need to ignore the alignment of the html string and force all text to be justified.

im tried this

Example2.HorizontalAlignment = Element.ALIGN_JUSTIFIED;

but doesnt work .

Upvotes: 0

Views: 627

Answers (1)

Bruno Lowagie
Bruno Lowagie

Reputation: 77606

In the first example, you're working in "text mode" and the properties of the cell are respected.

As soon as you use AddElement (), you're working in "composite mode" and the properties of the cell are ignored (as documented in my book). Instead, the properties of the separate elements are used.

In answer to your question: you shouldn't define the alignment at the level of the cell, but at the level of the element.

Upvotes: 1

Related Questions