iTextSharp - 是否可以在同一单元格中为文本设置不同的对齐方式 [英] iTextSharp - Is it possible to set a different alignment in the same cell for text

查看:133
本文介绍了iTextSharp - 是否可以在同一单元格中为文本设置不同的对齐方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个单元格和同一行中,我必须添加两个文本(名称和日期)。
第一个文本片段必须在左侧页面,第二个在右侧,所有内容必须在一行中。
我试过用段落 s, s和短语 s但我不知道怎么做。

In one cell and on the same line, I must add two text (name and date). The first snippet of text must be on the left page side, the second one on the right, and everything must be in one line. I've tried used Paragraphs, Chunks and Phrases but I don't know how to do it.

推荐答案

如果你想分开两件文本在同一个短语段落中,你必须创建一个我经常称为 glue

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();
}

结果如下:

如您所见,特殊我们已创建分隔字符串 leftright

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

这篇关于iTextSharp - 是否可以在同一单元格中为文本设置不同的对齐方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆