aspose-words / Aspose.Words-for-Java

Aspose.Words for Java examples, plugins and showcases
https://products.aspose.com/words/java
MIT License
401 stars 206 forks source link

Error in compressed image example on official website #102

Open pubil opened 1 year ago

pubil commented 1 year ago

https://products.aspose.com/words/zh/java/compress/

doc.cleanup();

NodeCollection nodes = doc.getChildNodes(NodeType.SHAPE, true);
for (Shape shape : (Iterable) nodes)
{
    if (shape.isImage())
    {
// 由开发人员选择用于图像压缩的库。
        BufferedImage image = ImageIO.read(shape.getImageData().toStream());

// 压缩图像并将其设置回形状。
        shape.getImageData().setImage("yourCompressedImage");
    }
}

OoxmlSaveOptions saveOptions = new OoxmlSaveOptions();
saveOptions.setCompressionLevel(CompressionLevel.MAXIMUM);

doc.save("Output.docx", saveOptions);

In this example, using this code to report an error Required type: Object Provided: Shape

截图20230906181322 c6b63a4df7.png…]()

my maven

            <groupId>com.aspose</groupId>
            <artifactId>aspose-words</artifactId>
            <version>22.11</version>
            <classifier>jdk17</classifier>
        </dependency>
        <dependency>
            <groupId>com.aspose</groupId>
            <artifactId>aspose-words</artifactId>
            <version>22.11</version>
            <classifier>javadoc</classifier>
        </dependency>
aspose-words-gists commented 1 year ago

@pubil Thanks for notice this. Just change (Iterable) nodes to (Iterable<Shape>) nodes. We will fix it.

pubil commented 1 year ago

@pubil Thanks for notice this. Just change (Iterable) nodes to (Iterable<Shape>) nodes. We will fix it.

Can you provide a detailed image compression algorithm

AlexNosk commented 12 months ago

@pubil Images compression is out of Aspose.Words scope. Using Aspose.Words you can extract the original image bytes from the shape, then use some third party tool to compress the image and then using Aspose.Words set the compressed image to the shape.