iTextSharp - 是否可以在同一单元格中为文本设置不同的对齐方式 [英] iTextSharp - Is it possible to set a different alignment in the same cell for text
问题描述
在一个单元格和同一行中,我必须添加两个文本(名称和日期)。
第一个文本片段必须在左侧页面,第二个在右侧,所有内容必须在一行中。
我试过用段落
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 Paragraph
s, Chunk
s and Phrase
s 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();
}
结果如下:
如您所见,特殊块
我们已创建分隔字符串
left
和right
。
As you can see, the special Chunk
we've created separates the Strings
"left"
and "right"
.
这篇关于iTextSharp - 是否可以在同一单元格中为文本设置不同的对齐方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!