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.

Tue Oct 24, 2017 2:04 pm

Hi everyone,
I'm trying to merge multiple file types(.doc .docx .pdf .msg .jpg .xls .xcell , etc.) in one single .pdf file. For testing the library I used the CS->Win Forms->Merge demo project. I modified the project so that I can merge multiple files instead of 2.
The problem I have is that the only file types I can merge are .txt and .docx. If I try to merge any other type I get an exception (System.Exception occurred: Cannot detect current file type). Also If I change the FileFormat to the exact type of the file I'm loading I get same Exception. :roll:
I want to make sure works as told before purchasing the library.

Here is my code:

Code: Select all
private void button1_Click(object sender, EventArgs e)
        {
            List<string> filePaths = new List<string>();
            for (int i = 0; i < 5; i++)
            {
                filePaths.Add(OpenFile());
            }

            //Create word document
            Document document = new Document();
            document.LoadFromFile(filePaths[0],FileFormat.Auto);

            for (int i = 1; i < filePaths.Count; i++)
            {
                Document documentMerge = new Document();
                documentMerge.LoadFromFile(filePaths[i],FileFormat.Auto);

                foreach (Section sec in documentMerge.Sections)
                {
                    document.Sections.Add(sec.Clone());
                }
            }
            //Save doc file.
            document.SaveToFile("Sample.pdf", FileFormat.PDF);

            //Launching the MS Word file.
            WordDocViewer("Sample.pdf");
        }

bogdansorin
 
Posts: 1
Joined: Fri Sep 29, 2017 12:49 pm

Wed Oct 25, 2017 3:21 am

Hi bogdansorin,

Thanks for your inquiry.
As for your requirement, you need to use Spire.Office. Different type files need to use corresponding product, and here are guides for your kind reference.
https://www.e-iceblue.com/Tutorials/Spi ... B.NET.html
And for the image, please insert it into word or PDF, then merge the files.
https://www.e-iceblue.com/Tutorials/Spi ... B.NET.html
https://www.e-iceblue.com/Tutorials/Spi ... o-PDF.html
And for .msg file format, sorry that there is no direct way to convert it to PDF, you could get the content from it via Spire.Email then add the text in word via Spire.Doc, then convert and merge files.
https://www.e-iceblue.com/Tutorials/Spi ... B.NET.html
If there is still issue, please provide us with the files which you want to merge for further investigation.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Return to Spire.Doc