PDFBox-防止注释出现在叠加层顶部

时间:2020-04-12 08:39:09

标签: java pdfbox

我正在将一个pdf覆盖在另一个pdf上。 我遇到的问题是“背景” pdf注释浮在“前景”页面上方。

是否有一种方法可以使注释变平或防止其在叠加层上方浮动? 这是一个示例:黑色文字应覆盖红色注释框。

text should be overlaying the square

我正在使用的代码:

    PDDocument baseDocument = PDDocument.load(new File("examples/test/base.pdf"));;
    PDDocument overlayDocument = PDDocument.load(new File("examples/test/overlay.pdf"));

    Iterator<PDPage> baseDocumentIterator = baseDocument.getPages().iterator();
    Iterator<PDPage> overlayIterator = overlayDocument.getPages().iterator();

    while(baseDocumentIterator.hasNext() && overlayIterator.hasNext()) {
        PDPage backing = baseDocumentIterator.next();
        List<PDAnnotation> annotations = backing.getAnnotations();
        for (PDAnnotation a :annotations) {
            a.setLocked(true);
            a.setReadOnly(true);
        }
    }

    PDAcroForm acroForm = baseDocument.getDocumentCatalog().getAcroForm();
    if (acroForm != null) {
        acroForm.flatten();
    }
    Overlay overlay = new Overlay();
    overlay.setOverlayPosition(Overlay.Position.FOREGROUND);
    overlay.setInputPDF(baseDocument);
    overlay.setAllPagesOverlayPDF(overlayDocument);

    Map<Integer, String> ovmap = new HashMap<Integer, String>();
    overlay.overlay(ovmap);

    AccessPermission ap = new AccessPermission();
    ap.setCanExtractContent(false);
    ap.setCanFillInForm(false);
    ap.setCanModify(false);
    ap.setReadOnly();
    ap.setCanModifyAnnotations(false);
    StandardProtectionPolicy standardPP = new StandardProtectionPolicy("", "", ap);
    standardPP.setEncryptionKeyLength(128);
    baseDocument.protect(standardPP);
    baseDocument.save("examples/test/output.pdf");
    baseDocument.close();
    overlayDocument.close();

我可以做些什么来使注释块出现在叠加层后面吗?

Example pdfs

0 个答案:

没有答案