We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Issue on image extraction

Hi Team,

My requirement is to extract the image based on the caption and save into new document.
In my source document some of the images are present in landscape orientation but it can be extract in portrait orientation in destination document .so, please kindly help me to extract image based on the image height and width without using page splitter

source document: test.zip (277.4 KB)

actual output: actual output.zip (67.5 KB)

Thanks and regards,
priyanga G

@priyanga,

Thanks for your inquiry. You can use PageSetup.Orientation to get or set the orientation of the page. Please check the following code example. Hope this helps you.

Document doc = new Document(MyDir + "test.docx");
int i=1;
NodeCollection shapes = doc.getChildNodes(NodeType.SHAPE, true);
for (Shape shape : (Iterable<Shape>) shapes)
{
    Document dstDoc = new Document();
    NodeImporter importer = new NodeImporter(doc, dstDoc, ImportFormatMode.KEEP_SOURCE_FORMATTING);
    Node newNode = importer.importNode(shape, true);
    dstDoc.getFirstSection().getBody().getFirstParagraph().appendChild(newNode);
    dstDoc.getFirstSection().getPageSetup().setOrientation(shape.getParentParagraph().getParentSection().getPageSetup().getOrientation());
    dstDoc.save(MyDir + "output"+i+".docx");
    i++;
}

Hi @tahir.manzoor,

Thanks for your feedback.

It’s working fine.

Thanks & regards,
Priyanga G

@priyanga,

Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.