Home > Mobile >  PDFBox I need to wrap the link tags with reference tag
PDFBox I need to wrap the link tags with reference tag

Time:10-14

I need to wrap the link tags with the reference tag.

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;
}

And it does the structural changes. But in PAC3 it shows below error,

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

Please help me to solve the problem. Sample PDF here.

CodePudding user response:

parentNode.removeKid(pdStructureElement);

Should be done before "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;
        }
  • Related