Hi Team,
My requirement is to extract the images and saved in new document.
My issue some of the images are extracted with different page properties.so i am not able to get the images as source document .So,please kindly help me to extract images with page properties.
source document: Chapter7_Chiabrando_Rinaudo.zip (1.5 MB)
actual output document:output1.zip (1.5 MB)
expected output document:ExpectedOutput.zip (1.5 MB)
Thanks & regards,
priyanga G
@priyanga,
Thanks for your inquiry. Please use the following code example to get the desired output. Hope this helps you.
Document doc = new Document(MyDir + "Chapter7_Chiabrando_Rinaudo.docx");
int i= 1;
for (Paragraph paragraph : (Iterable<Paragraph>) doc.getChildNodes(NodeType.PARAGRAPH, true))
{
if(paragraph.toString(SaveFormat.TEXT).trim().startsWith("Fig"))
{
Node previousPara = paragraph.getPreviousSibling();
while (previousPara != null
&& previousPara.getNodeType() == NodeType.PARAGRAPH
&& previousPara.toString(SaveFormat.TEXT).trim().length() == 0 &&
((Paragraph)previousPara).getChildNodes(NodeType.SHAPE, true).getCount() == 0)
{
previousPara = previousPara.getPreviousSibling();
}
if(previousPara != null)
{
if (previousPara != null && previousPara.getNodeType() == NodeType.PARAGRAPH
&& ((Paragraph) previousPara).getChildNodes(NodeType.SHAPE, true).getCount() > 0)
{
Document dstDoc = new Document();
dstDoc.removeAllChildren();
Section section = ((Paragraph) previousPara).getParentSection();
NodeImporter importer = new NodeImporter(doc, dstDoc, ImportFormatMode.KEEP_SOURCE_FORMATTING);
Node newNode = importer.importNode(section, false);
dstDoc.getSections().add(newNode);
dstDoc.updatePageLayout();
newNode = importer.importNode(previousPara, true);
dstDoc.getFirstSection().getBody().appendChild(newNode);
dstDoc.acceptAllRevisions();
dstDoc.save(MyDir + "output"+i+".docx");
}
}
}
}
Hi @tahir.manzoor,
Thank you very much…
It’s working fine.
Thanks & regards,
Priyanga G
@priyanga,
Thanks for your feedback. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.