-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
Merge pull request #324 from SyncfusionExamples/881083-Preserve-merge…
…d-documents-in-new-page 881083-Add sample Preserve-merged-documents-in-new-page
Showing
6 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
...ment/Preserve-merged-documents-in-new-page/.NET/Preserve-merged-documents-in-new-page.sln
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 added
BIN
+155 KB
...ents-in-new-page/.NET/Preserve-merged-documents-in-new-page/Data/DestinationDocument.docx
Binary file not shown.
Binary file added
BIN
+37.5 KB
...documents-in-new-page/.NET/Preserve-merged-documents-in-new-page/Data/SourceDocument.docx
Binary file not shown.
1 change: 1 addition & 0 deletions
1
...e-merged-documents-in-new-page/.NET/Preserve-merged-documents-in-new-page/Output/.gitkeep
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
27 changes: 27 additions & 0 deletions
27
...e/.NET/Preserve-merged-documents-in-new-page/Preserve-merged-documents-in-new-page.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
38 changes: 38 additions & 0 deletions
38
...eserve-merged-documents-in-new-page/.NET/Preserve-merged-documents-in-new-page/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |