iTextSharp - Is it possible to set a different alignment in the same cell for text

你说的曾经没有我的故事 提交于 2019-12-07 01:51:27

If you want to separate two pieces of text in the same Phrase or Paragraph, you have to create a Chunk I often refer to as glue:

Chunk glue = new Chunk(new VerticalPositionMark());

You can use this glue like this:

public void createPdf(String dest) throws IOException, DocumentException {
    Document document = new Document();
    PdfWriter.getInstance(document, new FileOutputStream(dest));
    document.open();
    Chunk glue = new Chunk(new VerticalPositionMark());
    PdfPTable table = new PdfPTable(1);
    Phrase p = new Phrase();
    p.add("Left");
    p.add(glue);
    p.add("Right");
    table.addCell(p);
    document.add(table);
    document.close();
}

The result looks like this:

As you can see, the special Chunk we've created separates the Strings "left" and "right".

Just use two paragraphs, chunks or phrases. If you are trying to do it with just one of the three, you are limited. Just define another text field to be added to the page. You can use any combination of three, and set the location on the page to reflect your requirements.

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