I observe strange behavior of LayoutCollector when saving Word document to PDF.
Given WORD document structure (it’s just working example, the exact structure does not matter):
- Document
-
- Section
-
-
- Body
-
-
-
-
- Paragraph
-
-
-
-
-
-
- Shape
-
-
-
-
-
-
-
- StructuredDocumentTag (Rich Text)
-
-
-
-
-
-
-
-
- Run
-
-
-
-
If you call LayoutCollector’s getStartPageIndex for the shape before changing text of the Run node then you will see the text is changed in docx document and no changes in PDF document.
Aspose Words library version: 20.12
I created minimal reproducible code example:
// Set license first.
// Creates paragraph with shape and SDT (Rich Text) nodes inside it.
var wordDocument = new Document();
var body = wordDocument.getSections().get(0).getBody();
var paragraph = new Paragraph(wordDocument);
body.appendChild(paragraph);
var shape = new Shape(wordDocument, ShapeType.TEXT_PLAIN_TEXT);
shape.getTextPath().setText("Image text");
paragraph.appendChild(shape);
var sdt = new StructuredDocumentTag(wordDocument, SdtType.RICH_TEXT, 1);
paragraph.appendChild(sdt);
var layoutCollector = new LayoutCollector(wordDocument);
// Comment out next line to see the difference.
layoutCollector.getStartPageIndex(shape);
var run = (Run) sdt.getChild(NodeType.RUN, 0, true);
run.setText("New RUN text");
wordDocument.save("test.docx");
wordDocument.save("test.pdf", SaveFormat.PDF);