Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
Aspose.Words allows users to work with images in a very flexible way. In this article, you can explore only some of the possibilities of working with images.
All images are stored inside Shape nodes in a Document. To extract all images or images having a specific type from the document, follow these steps:
This example lets you add the same or different barcodes on all or specific pages of a Word document. There is no direct way to add barcodes on all pages of a document but you can use moveToSection, moveToHeaderFooter and insertImage methods to move to any section or headers/footers and insert the barcode images as you can see in the following code.
The following code example shows how to insert a barcode image on each page of a document:
The aspect ratio of a geometric shape is the ratio of its sizes in different dimensions. You can lock the aspect ratio of an image using AspectRatioLocked. The default value of the shape’s aspect ratio depends on the ShapeType. It is true for ShapeType.Image and false for other shape types.
The following code example shows how to work with aspect ratio:
If you want the actual bounding box of the shape as rendered on the page, you can achieve this by using the BoundsInPoints property.
The following code example shows how to use this property:
The cropping of an image usually refers to the removal of the unwanted outer parts of an image to help improve the framing. It is also used for the removal of some of the portions of an image to increase the focus on a particular area.
The following code example shows how to achieve this using Aspose.Words API:
Aspose.Words provides functionality to save all the available images in a document to WMF format while converting DOCX to RTF.
The following code example shows how to save images as WMF with RTF save options:
Q: How can I extract all images from a Word document using Aspose.Words for Java?
A: Load the document, retrieve all Shape nodes with document.getChildNodes(NodeType.SHAPE, true), iterate the collection, check shape.hasImage(), then obtain the image bytes via shape.getImageData().getImageBytes() and write them to files.
Q: What is the recommended way to add a barcode image to every page of a document?
A: Use DocumentBuilder to navigate to each section’s header or footer with moveToHeaderFooter(HeaderFooterType.HEADER_PRIMARY) (or footer), then call insertImage(byte[]) with the barcode image data. Repeat for all sections to place the barcode on each page.
Q: How do I lock the aspect ratio of an image after inserting it?
A: After inserting the image, the returned Shape object represents the picture. Call shape.setAspectRatioLocked(true) to keep the original width‑to‑height proportion when the shape is resized.
Q: Can I crop an image that is already inside a Word document?
A: Yes. Obtain the Shape that contains the image and use the cropping properties: shape.getImageData().setCropTop(value), setCropBottom(value), setCropLeft(value), and setCropRight(value). The values are specified as percentages (0.0 to 1.0).
Q: How can I save all images in a document as WMF when converting to RTF?
A: Create an RtfSaveOptions instance, set options.setImageSavingCallback(new ImageSavingCallback() { … }) and inside the callback save each image with ImageSaveOptions.setImageFormat(ImageFormat.WMF). Then call document.save("output.rtf", options) to produce an RTF where all images are stored as WMF.
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.