PDFBox 我需要用参考标签包装 link 标签

PDFBox I need to wrap the link tags with reference tag

我需要用 reference 标签包裹 link 标签。

private static PDStructureElement wrapInElement(String structType, PDStructureElement pdStructureElement) {
    PDStructureNode parentNode = pdStructureElement.getParent();
    PDStructureElement structureElement = null;
    if (parentNode!=null && parentNode instanceof PDStructureElement)  {
        structureElement = new PDStructureElement(structType,parentNode);
        structureElement.setElementIdentifier("wrap"+noteID++);
        parentNode.insertBefore(structureElement,pdStructureElement);
        structureElement.setParent(parentNode);
        structureElement.appendKid(pdStructureElement);
        parentNode.removeKid(pdStructureElement);
    }
    return structureElement;
}

它会进行结构更改。但在 PAC3 中显示以下错误,

"Link" annotation is not nested inside a "Link" structure element

请帮我解决问题。 Sample PDF here.

parentNode.removeKid(pdStructureElement);

应该在“appendkid”之前完成。

private static PDStructureElement wrapInElement(String structType, PDStructureElement pdStructureElement) {
            PDStructureNode parentNode = pdStructureElement.getParent();
            PDStructureElement structureElement = null;
            if (parentNode!=null && parentNode instanceof PDStructureElement)  {
                structureElement = new PDStructureElement(structType,parentNode);
                parentNode.insertBefore(structureElement,pdStructureElement);
                structureElement.setParent(parentNode);
                parentNode.removeKid(pdStructureElement);
                structureElement.appendKid(pdStructureElement);
            }
            return structureElement;
        }