Hi,
I’m not sure what is wrong but when I remove a watermark from the document using ASPOSE, I cannot open it in Open XML SDK Tool. We use this tool very often to see the structure and/or debug issues but now we cannot use it.
Code to remove watermark:
private static void RemoveWatermark(Document doc, String watermarkText) {
NodeCollection headerColl = doc.getChildNodes(NodeType.HEADER_FOOTER, true);
if (headerColl == null || headerColl.getCount() == 0)
return;
Node[] headerNodes = headerColl.toArray();
int headerCount = headerNodes.length;
for (int i = 0; i < headerCount; i++) {
HeaderFooter header = (HeaderFooter) headerNodes[i];
if (header.isHeader()) {
NodeCollection shapeColl = doc.getChildNodes(NodeType.SHAPE, true);
if (shapeColl.getCount() > 0) {
Node[] shapeNodes = shapeColl.toArray();
for (Node node : shapeNodes) {
if (node instanceof Shape) {
Shape shape = (Shape) node;
if (shape.getName().startsWith("MyWaterMark_")
|| shape.getTextPath().getText().equalsIgnoreCase(watermarkText)) {
shape.remove();
}
}
}
}
}
}
}
Thanks,
Mahesh