【发布时间】:2017-08-05 12:39:59
【问题描述】:
我正在使用以下方法创建 PDF 文件:
private void createPdf() throws IOException {
PDDocument doc = new PDDocument();
PDPage page = new PDPage();
doc.addPage(new PDPage());
PDPageContentStream content = new PDPageContentStream(doc, page);
content.beginText();
content.setFont(PDType1Font.HELVETICA, 26);
content.showText("Example Text");
content.endText();
content.close();
doc.save("report.pdf");
doc.close();
}
它会创建一个带有白页的新文件,但没有显示任何文本。怎么了?
我使用 Apache PDFBox 2.0.7。
【问题讨论】:
-
你看过页面底部了吗?
-
Vega,@Tilman 暗示的是您没有为文本指明任何位置。因此,它在 (0,0) 处绘制,如果您的代码位于页面的左下角。
-
我仔细检查过,但页面上什么也没有。感谢您的提示。还有其他想法吗?