[英]How to add line break in PDFbox JAVA
我正在生成一个 PDF 文件,其中包含一些注释、单元格、表格...我在 JAVA 中使用 PDFbox
我想在名为“escComments”的字符串中添加一个换行符,它包含一个注释数组。
我试过“\n”、“\r”、“System.getProperty(“line.separator”)”但没有任何效果。
这是我的代码:
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”来拆分字符串并将文本 position 移动到下一行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.