Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Wed Jun 07, 2023 6:19 am

Hi, I am merging multiple documents, some of which have images. When I checked the final merged document via Google Docs, the format was retained, and I could see the images displayed. But the image is not displayed when I view it via Microsoft Word. This is the code snippet that I just followed from the Spire.Doc documentation:

Code: Select all
 Document doc = new Document(path);
           foreach (string element in filePaths)
                   {
                      if (File.Exists(element))
                          {
                              doc.InsertTextFromFile(element, FileFormat.Docx2013);
                           }
                    }

           doc.SaveToFile($"{output}{fileName}{fileExtension}", FileFormat.Docx2013);

yam1eDev
 
Posts: 1
Joined: Tue Jun 06, 2023 11:28 am

Wed Jun 07, 2023 7:53 am

Hello,

Thank you for your inquiry.
I simulated two Word documents and tested your code using the latest version of Spire.Doc(Spire.Doc Pack(hot fix) Version:11.5.12), but I couldn't reproduce the issue you mentioned. If you are not using the latest version, please test with it first. If the issue still exists after testing, please provide your source Word file and your application type(such as Console app .Net Framework 4.5) for further investigation. You could attach them here or send them to us via email ([email protected]). Thanks in advance.
Additionally, you can use the following code to merge Word files.
Code: Select all
 Document doc = new Document(path);
 foreach (string element in filePaths)
 {
     if (File.Exists(element))
     {
         Document newDoc = new Document();
         newDoc.LoadFromFile(element, FileFormat.Auto);
         newDoc.KeepSameFormat = true;
         foreach (Section section in newDoc.Sections)
         {
             doc.Sections.Add(section.Clone());
         }
     }
 }
 doc.SaveToFile($"{output}{fileName}{fileExtension}", FileFormat.Docx2013);

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Return to Spire.Doc