How justify text using iTextSharp?

与世无争的帅哥 提交于 2019-12-01 17:12:24

Ah, I get it, you mean "justified" instead of "adjusted". I updated your question. It's actually pretty easy. Basically it depends on the type of content that you're adding and whether that content supports this concept in the first place. Assuming that you have basic paragraphs you can set the Alignment property on them before adding them in your main loop:

foreach (var htmlElement in parsedHtmlElements){
    //If the current element is a paragraph
    if (htmlElement is Paragraph){
        //Set its alignment
        ((Paragraph)htmlElement).Alignment = Element.ALIGN_JUSTIFIED;
    }
    doc.Add(htmlElement);
}

There's two types of justification, Element.ALIGN_JUSTIFIED and Element.ALIGN_JUSTIFIED_ALL. The second is the same as the first except that it also justifies the last line of text which you may or may not want to do.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!