【发布时间】:2019-01-16 12:42:22
【问题描述】:
我刚刚从 PdfBox 1.8 过渡到 2.0.0,并且有相当大的差异。在现有的 pdf 页面上写文本之前,我使用了 drawString。在 2.0.0 中不推荐使用绘制字符串,但 showText 在块文本中不起作用。
我在 1.8 中的代码:
contentStream.beginText()
contentStream.moveTextPositionByAmount(250, 665)
contentStream.drawString("1 2 3 4 5 6 7 8 9 1 0")
contentStream.endText()
我在 2.0 中的代码
PDDocument newPdf=null
newPdf=PDDocument.load(sourcePdfFile)
PDPage firstPage=newPdf.getPage(0)
PDPageContentStream contentStream = new PDPageContentStream(newPdf, firstPage, PDPageContentStream.AppendMode.APPEND,true,true)
contentStream.setFont(pdfFont, fontSize)
contentStream.beginText()
contentStream.lineTo(200,685)
contentStream.showText("John")
contentStream.endText()
但它不起作用......
任何人都知道如何在 1.8 中编写文本
【问题讨论】: