using System;
using System.IO;
using SautinSoft.Document;
namespace Sample
{
class Sample
{
static void Main(string[] args)
{
MergeTwoDocuments();
}
public static void MergeTwoDocuments()
{
string singleFilePath = "Single.docx";
string[] supportedFiles = new string[] { @"..\..\..\example.docx", @"..\..\..\example.pdf" };
DocumentCore dcSingle = new DocumentCore();
foreach (string file in supportedFiles)
{
DocumentCore dc = DocumentCore.Load(file);
Console.WriteLine("Adding: {0}...", Path.GetFileName(file));
ImportSession session = new ImportSession(dc, dcSingle, StyleImportingMode.KeepSourceFormatting);
foreach (Section sourceSection in dc.Sections)
{
Section importedSection = dcSingle.Import<Section>(sourceSection, true, session);
if (dc.Sections.IndexOf(sourceSection) == 0)
importedSection.PageSetup.SectionStart = SectionStart.NewPage;
dcSingle.Sections.Add(importedSection);
}
}
dcSingle.Save(singleFilePath);
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(singleFilePath) { UseShellExecute = true });
}
}
}
Document .Net can help you to merge documents of different formats: PDF, DOCX, RTF, Text and HTML, etc.
The product supports various platforms, including Windows, Linux, macOS, and Docker, and is compatible with .NET 8, 7, 6, 5, Standard 2, Core 2x & 3x, and Framework 4.6.2+.