Represents an import session that maps styles (and other referenced objects) between two different
DocumentCore instances.
Inheritance Hierarchy SystemObject
SautinSoft.DocumentImportSession
Namespace: SautinSoft.DocumentAssembly: SautinSoft.Document (in SautinSoft.Document.dll) Version: 2024.10.24
Syntax public sealed class ImportSession
Public NotInheritable Class ImportSession
The ImportSession type exposes the following members.
Constructors Properties | Name | Description |
---|
| DestinationDocument |
Gets the destination document.
|
| ImportMode |
Gets or sets style importing mode.
|
| Mapping |
Gets the dictionary that contains styles mapping.
Key is style in source document. Value is style in destination document.
|
| SourceDocument |
Gets the source document.
|
TopExample See Developer Guide: How to merge two documents: DOCX and PDF
How to merge two documents: DOCX and PDF in C#
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 });
}
}
}
How to merge two documents: DOCX and PDF in VB.Net
Imports System
Imports System.IO
Imports SautinSoft.Document
Module Sample
Sub Main()
MergeTwoDocuments()
End Sub
Sub MergeTwoDocuments()
Dim singleFilePath As String = "Single.docx"
Dim supportedFiles() As String = {"..\..\..\example.docx", "..\..\..\example.pdf"}
Dim dcSingle As New DocumentCore()
For Each file As String In supportedFiles
Dim dc As DocumentCore = DocumentCore.Load(file)
Console.WriteLine("Adding: {0}...", Path.GetFileName(file))
Dim session As New ImportSession(dc, dcSingle, StyleImportingMode.KeepSourceFormatting)
For Each sourceSection As Section In dc.Sections
Dim importedSection As Section = dcSingle.Import(Of Section)(sourceSection, True, session)
If dc.Sections.IndexOf(sourceSection) = 0 Then
importedSection.PageSetup.SectionStart = SectionStart.NewPage
End If
dcSingle.Sections.Add(importedSection)
Next sourceSection
Next file
dcSingle.Save(singleFilePath)
System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(singleFilePath) With {.UseShellExecute = True})
End Sub
End Module
See Also