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