itext块互相写
我有一个简单的代码,将句子(代码中的命名内容)分为令牌,然后在PDF文件中写入令牌,但每个句子都在新行中。
Document document = new Document(PageSize.A4, 20, 20, 20, 20);
PdfWriter.getInstance(document, new FileOutputStream("ticket.pdf"));
document.open();
Font font = FontFactory.getFont(FontFactory.COURIER, 16, BaseColor.BLACK);
String[] tokens = content.split("\\|");
for (String token : tokens) {
Chunk chunk = new Chunk(token, font);
document.add(chunk);
document.add(Chunk.NEWLINE);
}
document.close();
但是,当我打开结果pdf文件时,所有令牌(块)都在第一行中互相写入:
有人可以指向我我在这里做错了什么?代码用Java 11用Spring Boot编写,Itext版本为5.5.10
I have a simple piece of code that splits a sentence (named content in the code) into tokens and then writes tokens in pdf file, but each in new line.
Document document = new Document(PageSize.A4, 20, 20, 20, 20);
PdfWriter.getInstance(document, new FileOutputStream("ticket.pdf"));
document.open();
Font font = FontFactory.getFont(FontFactory.COURIER, 16, BaseColor.BLACK);
String[] tokens = content.split("\\|");
for (String token : tokens) {
Chunk chunk = new Chunk(token, font);
document.add(chunk);
document.add(Chunk.NEWLINE);
}
document.close();
But when I open the result pdf file, all of the tokens (chunks) are written over each other in the first line, like this:
Can anyone point to me what am I doing wrong here? Code is written in Spring Boot with Java 11, and iText version is 5.5.10
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论