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

Free Support Forum - aspose.com

Read Images from one doc file and put it into another

Hi

How can we read only images or visio diagrams from one doc file and paste these into another doc file.

Hi Saurabh,


Thanks for your inquiry. Please use the following code:

Document doc = new Document(filePath);

Document doc2 = new Document();

foreach (Shape img in doc.GetChildNodes(NodeType.Shape, true))

{

Shape imported = (Shape)doc2.ImportNode(img, true);

doc2.FirstSection.Body.FirstParagraph.AppendChild(imported);

}

doc.Save(MyDir + @"16.6.0.docx");


Hope, this helps.

Best regards,

Hi

Thanks for your reply.it works for me.
i need to know one thing that how can we read floating text which is written below image.

Hi Saurabh,

Thanks for your inquiry. Please use Node.ToString(SaveFormat.Text) method to get the text of a Node. Hope this helps you.

If you face any issue, please share your input document here for our reference? We will then provide you more information about your query along with code.

Hi

please find attachment file. i want “FIGURES 14 | SB_VIEW G_CAPTURE” and “TASK 2, SHEET 8: Group 1 - KIT - S46 FWD WAP-4 EQUIPMENT INSTL – 824J3460-1” text in image.or is there any method to copy whole content of page to another word docuement.

Hi Saurabh,

Thanks for your inquiry. If the shared text is not part of image, you can get the text using Node.ToString(SaveFormat.Text) method. You can also copy the contents of one document into another document using Aspose.Words. Following code example shows how to import text of one document into another.

Could you please share your input and expected output word documents here for our reference? We will then provide you more information about your query along with code.


Document dstDoc = new Document(MyDir + "dstDoc.docx");

Document srcDoc = new Document(MyDir + "srcDoc.docx");

NodeImporter importer = new NodeImporter(srcDoc, dstDoc, ImportFormatMode.KeepSourceFormatting);

foreach (Paragraph node in srcDoc.GetChildNodes(NodeType.Paragraph, true))

{

Node importNode = importer.ImportNode(node, true);

dstDoc.FirstSection.Body.AppendChild(importNode);

}

dstDoc.Save(MyDir + "Out.docx");

Hi

Please find attachment file. i want 2 things in o/p file.
1. any page contains 2 images that will come same in output file page also.
2. orientation of page will be same like if source image is in portrait than page in o/p file will also be in
portrait.

Hi Saurabh,

Thanks for your inquiry. As per my understanding, you want to insert whole page of input document into another document with same page orientation. If this is the case, we suggest you following solution.


1) Use PageSplitter utility to extract the specific page of input document.
2) DocumentPageSplitter.GetDocumentOfPage(int page) returns the Document which contains the contents of specific page of input document.
3) Once you have Document of specific page, please use Document.AppendDocument method to append the specified document to the end of another document.

Please check “PageSplitter” example project in Aspose.Words for .NET examples repository at GitHub. Following code example shows how to extract a page of input document and insert it at the end of another document. Hope this helps you.

Document doc = new Document(MyDir + “input.docx”);<o:p></o:p>

LayoutCollector layoutCollector = new LayoutCollector(doc);

PageSplitterExample.DocumentPageSplitter splitter = new PageSplitterExample.DocumentPageSplitter(layoutCollector);

Document pageDoc = splitter.GetDocumentOfPage(1);

Document dstDoc = new Document(MyDir + "dstDoc.docx");

dstDoc.AppendDocument(pageDoc, ImportFormatMode.KeepSourceFormatting);

dstDoc.Save(MyDir + "Out v16.6.0.docx");


If you still face problem, please share your expected output document and other document to which you want to insert extracted contents. We will then provide you more information about your query along with code.