使用newLineOf替换文本pdf pdfbox

时间:2017-07-10 12:33:31

标签: java pdfbox

如何使用pdfbox替换/覆盖当前文本。我有以下代码。如果我使用PDPageContentStream.AppendMode.OVERWRITE然后它说我试图覆盖,应该使用追加。因此将我的页面打印为空白。

WARN o.a.p.pdmodel.PDPageContentStream - You are overwriting an existing content, you should use the append mode

如果我使用PDPageContentStream.AppendMode.APPEND,则没有任何反应,页面显示为原始

    PDDocument doc = PDDocument.load(byteArr); // bytearr from file 

    try (PDPageContentStream contentStream = new PDPageContentStream(doc, doc.getPage(0), PDPageContentStream.AppendMode.OVERWRITE, false)) {

        contentStream.beginText();
        contentStream.setFont(PDType1Font.COURIER, 12);
        contentStream.newLineAtOffset(xLoc, yLoc); // Position of text i want to replace
        contentStream.showText("N/A"); // new text
        contentStream.endText();

    } catch (IOException ex) {
        ex.printStackTrace();
    }

所有流都相应关闭。关注https://www.tutorialspoint.com/pdfbox/pdfbox_adding_text.html

任何帮助将不胜感激。

0 个答案:

没有答案
相关问题