Skip to content

Commit

Permalink
Merge pull request #324 from SyncfusionExamples/881083-Preserve-merge…
Browse files Browse the repository at this point in the history
…d-documents-in-new-page

881083-Add sample Preserve-merged-documents-in-new-page
MohanaselvamJothi authored Jan 23, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
2 parents 6443fae + f7f1cc4 commit 4da7140
Showing 6 changed files with 88 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.12.35527.113 d17.12
MinimumVisualStudioVersion = 10.0.40219.1
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}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{5E219324-70AF-4788-A3F7-82260DCCE746}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5E219324-70AF-4788-A3F7-82260DCCE746}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5E219324-70AF-4788-A3F7-82260DCCE746}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5E219324-70AF-4788-A3F7-82260DCCE746}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>Preserve_merged_documents_in_new_page</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Syncfusion.DocIO.Net.Core" Version="*" />
</ItemGroup>

<ItemGroup>
<None Update="Data\DestinationDocument.docx">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Data\SourceDocument.docx">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Output\.gitkeep">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using Syncfusion.DocIO.DLS;
using Syncfusion.DocIO;
using System.Reflection.Metadata;

namespace Preserve_merged_documents_in_new_page
{
internal class Program
{
static void Main(string[] args)
{
using (FileStream sourceStreamPath = new FileStream(Path.GetFullPath(@"Data/SourceDocument.docx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
//Opens an source document from file system through constructor of WordDocument class.
using (WordDocument sourceDocument = new WordDocument(sourceStreamPath, FormatType.Automatic))
{
using (FileStream destinationStreamPath = new FileStream(Path.GetFullPath(@"Data/DestinationDocument.docx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
//Opens the destination document.
using (WordDocument destinationDocument = new WordDocument(destinationStreamPath, FormatType.Automatic))
{
//Sets the break-code of first section of source document
sourceDocument.Sections[0].BreakCode = SectionBreakCode.NewPage;
//Imports the contents of the source document to the destination document, and
//applies the formatting of surrounding content to the destination document.
destinationDocument.ImportContent(sourceDocument, ImportOptions.MergeFormatting);
//Creates file stream.
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"Output/Result.docx"), FileMode.Create, FileAccess.ReadWrite))
{
//Saves the Word document to file stream.
destinationDocument.Save(outputFileStream, FormatType.Docx);
}
}
}
}
}
}
}
}

0 comments on commit 4da7140

Please sign in to comment.