我使用PDFJet-Open-Source库来构建pdf.所以,我有几个问题:
1)如何将多行文本放在Cell中?
问题描述:目前我遇到的问题是我不能将多行文本放在Cell对象中.我尝试设置文本,"text1 \n text2..."但它没有任何影响.不幸的是,开源版本没有TextColumn和Paragraph类.
2)什么是CompositeTextLine以及如何使用它?
问题描述:也许我有错误的想象力,但我尝试做以下事情:
...
CompositeTextLine ctl = new CompositTextLine(0,0);
ctl.addComponent(new TextLine(f1,"MyText1"));
ctl.addComponent(new TextLine(f1,"MyText2"));
ctl.addComponent(new TextLine(f1,"MyText3"));
Cell cell = new Cell(f1);
cell.setCompositeTextLine(ctl);
...
Run Code Online (Sandbox Code Playgroud)
我希望看到Cell中有几行,但我什么都没看到.此外,如果我添加该行table.wrapAroundCellText(),我有NullPointerException.如果我打电话ctl.drawOn(page),我只是观察:"MyText1 MyText2 MyText3"没有换行.
更新:我发现了TextBox类,所以,如果我写:
TextBox textbox = new TextBox(f1);
textbox.setText("First Line \n Second Line");
textbox.drawOn(page);
Run Code Online (Sandbox Code Playgroud)
它将构建我想要的东西:
First Line
Second Line
Run Code Online (Sandbox Code Playgroud)
但我仍然对(1)和(2)的描述以及其中一些变体的可能性感兴趣,比如"如何在Cell中设置TextBox(或图像等),而不仅仅是单行?"
最后一个,请有人,请参考我在Java或C++中实现"文本对齐"算法.