Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WF-63391-Prepare blog for Word to PDF conversion in .NET Core platform #14

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28307.168
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mail-merged-Word-into-PDF", "Mail-merged-Word-into-PDF\Mail-merged-Word-into-PDF.csproj", "{060C9D44-A053-43CB-8A16-BFB8BCCCE580}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{060C9D44-A053-43CB-8A16-BFB8BCCCE580}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{060C9D44-A053-43CB-8A16-BFB8BCCCE580}.Debug|Any CPU.Build.0 = Debug|Any CPU
{060C9D44-A053-43CB-8A16-BFB8BCCCE580}.Release|Any CPU.ActiveCfg = Release|Any CPU
{060C9D44-A053-43CB-8A16-BFB8BCCCE580}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {BF422962-51A0-4C08-B7DB-51C26692639F}
EndGlobalSection
EndGlobal
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<RootNamespace>Mail_merged_Word_into_PDF</RootNamespace>
</PropertyGroup>

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

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

namespace Mail_merged_Word_into_PDF
{
class Program
{
static void Main(string[] args)
{
//Opens the Word template document
FileStream fileStreamPath = new FileStream(@"../../../Letter Formatting.docx", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
using (WordDocument document = new WordDocument(fileStreamPath, FormatType.Docx))
{
string[] fieldNames = { "ContactName", "CompanyName", "Address", "City", "Country", "Phone" };
string[] fieldValues = { "Nancy Davolio", "Syncfusion", "507 - 20th Ave. E.Apt. 2A", "Seattle, WA", "USA", "(206) 555-9857-x5467" };
//Performs the mail merge
document.MailMerge.Execute(fieldNames, fieldValues);
//Create instance for DocIORenderer for Word to PDF conversion
DocIORenderer render = new DocIORenderer();
//Converts Word document to PDF.
PdfDocument pdfDocument = render.ConvertToPDF(document);
//Release the resources used by the Word document and DocIO Renderer objects.
render.Dispose();
document.Dispose();
//Saves the PDF file.
FileStream outputStream = new FileStream(@"Ouput.pdf", FileMode.CreateNew, FileAccess.Write);
pdfDocument.Save(outputStream);
//Closes the instance of PDF document object.
pdfDocument.Close();
//Dispose the instance of FileStream.
outputStream.Dispose();
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28307.136
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Word-to-PDF-Batch-process", "Word-to-PDF-Batch-process\Word-to-PDF-Batch-process.csproj", "{2BD87830-E669-478E-AB71-D96123882EFC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{2BD87830-E669-478E-AB71-D96123882EFC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2BD87830-E669-478E-AB71-D96123882EFC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2BD87830-E669-478E-AB71-D96123882EFC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2BD87830-E669-478E-AB71-D96123882EFC}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C6634722-7F6B-43D8-875D-405DC8865D70}
EndGlobalSection
EndGlobal
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using System.IO;
using System.Threading.Tasks;
using Syncfusion.DocIO;
using Syncfusion.DocIO.DLS;
using Syncfusion.DocIORenderer;
using Syncfusion.Pdf;

namespace Word_to_PDF_Batch_process
{
class Program
{
static void Main(string[] args)
{
//Gets multiple word document from the data folder
var files = Directory.GetFiles(@"../../../Data/");
Parallel.ForEach(files, file =>
{
//Open the file as Stream
FileStream SourceStream = File.Open(file, FileMode.Open, FileAccess.Read);
//Loads file stream into Word document
WordDocument srcDoc = new WordDocument(SourceStream, FormatType.Automatic);
//Instantiation of DocIORenderer for Word to PDF conversion
DocIORenderer renderer = new DocIORenderer();
//Converts Word document into PDF document
PdfDocument pdfDocument = renderer.ConvertToPDF(srcDoc);
//Saves the PDF file
FileStream outputStream = new FileStream(@file + ".pdf", FileMode.OpenOrCreate, FileAccess.ReadWrite);
pdfDocument.Save(outputStream);
// Dispose the objects
pdfDocument.Close(true);
srcDoc.Close();
renderer.Dispose();
SourceStream.Dispose();
outputStream.Dispose();
});
Console.WriteLine("Process Completed!!");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<RootNamespace>Word_to_PDF_Batch_process</RootNamespace>
</PropertyGroup>

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

</Project>