Manually Resizing OLE document ignores page height and width settings when Track Changes enabled

I am trying to resize an embedded OLE with the following code. oleResized.docx will not output a document that is 300x300 but oleNotResized.docx will. The only difference between the two documents is that the oleResized.docx was slightly manually resized in Word. (dragging the corner).

oleNotResized.docx (29.0 KB)

oleResized.docx (29.2 KB)

//Document doc = new Document("oleNotResized.docx");
Document doc = new Document("oleResized.docx");

NodeCollection shapeNodes = doc.getChildNodes(NodeType.SHAPE, true);
Shape shape = (Shape) shapeNodes.get(0);
OleFormat oleFormat = shape.getOleFormat();
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
oleFormat.save(outStream);
byte[] docBytes = outStream.toByteArray();
InputStream inStream = new ByteArrayInputStream(docBytes);
Document embeddedDoc = new Document(inStream);
DocumentBuilder builder = new DocumentBuilder(embeddedDoc);

builder.getPageSetup().setPageHeight(300);
builder.getPageSetup().setPageWidth(300);

embeddedDoc.save("result.docx", SaveFormat.DOCX);

@faith113
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): WORDSNET-26953

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

Thank you,

Just a note if anyone else runs into this one. A possible workaround is to accept the revisions. But if you would like to keep them to only accept them where:

revision.getRevisionType() == RevisionType.FORMAT_CHANGE && revision.getParentNode().getNodeType() == NodeType.SECTION

This accepts the formatting change on the resized OLE that breaks the page resizing. It obviously may accept other format changes so use caution.

@faith113 Yes, the problem is causes by the revisions in the OLE object page setup. But still Aspose.Words looks like not correct, since changes made in the code are applied to the before version of page setup not after.

1 Like