【发布时间】:2017-01-15 16:21:27
【问题描述】:
我在 java 中使用 itext API 来创建和打印 PDF 文档中的动态内容。
下面是我需要在PDF文档中添加的动态内容。
This is first line.
This is second line.
This is third printed line.
This is fourth printed line.
#ACC004342-123
More information:
This is fifth printed line.
#ACC004342-123
This is Sixth printed line.
Some information goes here.
在上面显示的示例文本中,它们是#ACC004342-123 和更多信息之间的差距:我需要删除的行。
public static File createInformationPdf(final List<MyDocumentType> content) throws AccServiceException
{
Document document = null;
FileOutputStream fos = null;
try
{
final String prefix = "letter";
final File myPDF = File.createTempFile(prefix, ".pdf");
document = new Document(PageSize.LETTER);
fos = new FileOutputStream(temporaryPDF);
PdfWriter.getInstance(document, fos);
document.open();
Font font = new Font(Font.FontFamily.COURIER,10);
for (final MyDocumentType myDocument : content)
{
if (myDocument.getDocumentines() != null)
{
final DocumentLinesType documentLines = myDocument.getDocumentLines();
for (final String line : documentLines.getDocumentLine())
{
document.add(new Paragraph(line,font));
}
}
}
document.close();
return temporaryPDF;
}
catch (Exception e)
{
//log the exception
}
}
PS:上面是我的java代码,我只想删除#ACC004342-123和更多信息之间存在的更多空白行:行,然后在它们之间留一个空行.当我从 web 服务调用中获取该内容时,我需要在我的 java 代码中处理。希望我现在很清楚。谢谢。
【问题讨论】:
-
这比你上一个问题的描述更好。诚然:您现在承认自己是一个肮脏的编码员,但至少现在我们可以帮助您并解释您做错了什么。我们现在了解导致不需要的空白行的原因。