如何在PDFbox JAVA中添加换行符



im生成一个包含一些注释、单元格、表格的PDF文件。。。我在JAVA 中使用PDFbox

我想在我的字符串中添加一个换行符,它被称为";escComments";并且它包含一个Comments数组。

我试过";\n〃"\r"System.getProperty("行分隔符"("什么都不管用。

这是我的代码:

if (action.getCloseComment() != null) {
String escComments = action.getCloseComment();
escComments = escapeChars(escComments);


row.put( "COMENTARIOS", escComments);
}

我想为getCloseComment((中的每个评论添加一个换行符

try (PDPageContentStream contents = new PDPageContentStream(doc, page))
{
PDFont font = PDType1Font.HELVETICA;
contents.beginText();
contents.setFont(font, 12);
contents.newLineAtOffset(100, 700);
contents.showText(line1);
contents.newLineAtOffset(0, -50);
contents.showText(line2);
contents.newLineAtOffset(0, -50);
contents.showText(line3);
contents.endText();
}

您可以尝试"moveTextPositionByAmount"来拆分字符串并将文本位置移动到下一行。

最新更新