Skip to content

Commit 4da7140

Browse files
Merge pull request #324 from SyncfusionExamples/881083-Preserve-merged-documents-in-new-page
881083-Add sample Preserve-merged-documents-in-new-page
2 parents 6443fae + f7f1cc4 commit 4da7140

File tree

6 files changed

+88
-0
lines changed

6 files changed

+88
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.12.35527.113 d17.12
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Preserve-merged-documents-in-new-page", "Preserve-merged-documents-in-new-page\Preserve-merged-documents-in-new-page.csproj", "{5E219324-70AF-4788-A3F7-82260DCCE746}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{5E219324-70AF-4788-A3F7-82260DCCE746}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{5E219324-70AF-4788-A3F7-82260DCCE746}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{5E219324-70AF-4788-A3F7-82260DCCE746}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{5E219324-70AF-4788-A3F7-82260DCCE746}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<RootNamespace>Preserve_merged_documents_in_new_page</RootNamespace>
7+
<ImplicitUsings>enable</ImplicitUsings>
8+
<Nullable>enable</Nullable>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="Syncfusion.DocIO.Net.Core" Version="*" />
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<None Update="Data\DestinationDocument.docx">
17+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
18+
</None>
19+
<None Update="Data\SourceDocument.docx">
20+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
21+
</None>
22+
<None Update="Output\.gitkeep">
23+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
24+
</None>
25+
</ItemGroup>
26+
27+
</Project>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using Syncfusion.DocIO.DLS;
2+
using Syncfusion.DocIO;
3+
using System.Reflection.Metadata;
4+
5+
namespace Preserve_merged_documents_in_new_page
6+
{
7+
internal class Program
8+
{
9+
static void Main(string[] args)
10+
{
11+
using (FileStream sourceStreamPath = new FileStream(Path.GetFullPath(@"Data/SourceDocument.docx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
12+
{
13+
//Opens an source document from file system through constructor of WordDocument class.
14+
using (WordDocument sourceDocument = new WordDocument(sourceStreamPath, FormatType.Automatic))
15+
{
16+
using (FileStream destinationStreamPath = new FileStream(Path.GetFullPath(@"Data/DestinationDocument.docx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
17+
{
18+
//Opens the destination document.
19+
using (WordDocument destinationDocument = new WordDocument(destinationStreamPath, FormatType.Automatic))
20+
{
21+
//Sets the break-code of first section of source document
22+
sourceDocument.Sections[0].BreakCode = SectionBreakCode.NewPage;
23+
//Imports the contents of the source document to the destination document, and
24+
//applies the formatting of surrounding content to the destination document.
25+
destinationDocument.ImportContent(sourceDocument, ImportOptions.MergeFormatting);
26+
//Creates file stream.
27+
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Result.docx"), FileMode.Create, FileAccess.ReadWrite))
28+
{
29+
//Saves the Word document to file stream.
30+
destinationDocument.Save(outputFileStream, FormatType.Docx);
31+
}
32+
}
33+
}
34+
}
35+
}
36+
}
37+
}
38+
}

0 commit comments

Comments
 (0)