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.
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");
}