请问图片超过页面宽度,怎么自动调整

源文档:
文字文稿1.docx (28.3 KB)

请问文档中的图片怎么自动调整为适应宽度的大小

@ouchli 您可以使用以下代码更改形状宽度:

Document doc = new Document("input.docx");

Section section = doc.getFirstSection();
PageSetup pageSetup = section.getPageSetup();

double pageWidth = pageSetup.getPageWidth() - pageSetup.getLeftMargin() - pageSetup.getRightMargin();
for (Shape shape : (Iterable<Shape>) doc.getChildNodes(NodeType.SHAPE, true)) {
    if (shape.getWidth() > pageWidth)
        shape.setWidth(pageWidth);
}

doc.save("output.docx");