⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
Skip to content
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 Version 17
VisualStudioVersion = 17.14.36908.2 d17.14
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Convert_Word_to_Thumbnail-Image", "Convert_Word_to_Thumbnail-Image\Convert_Word_to_Thumbnail-Image.csproj", "{B7A7EDE2-1818-4C6A-9DBF-E1DEF995A6C3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B7A7EDE2-1818-4C6A-9DBF-E1DEF995A6C3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B7A7EDE2-1818-4C6A-9DBF-E1DEF995A6C3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B7A7EDE2-1818-4C6A-9DBF-E1DEF995A6C3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B7A7EDE2-1818-4C6A-9DBF-E1DEF995A6C3}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {ABE93116-3AB5-4CD8-87C0-8C646A6CDC8C}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">

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

<ItemGroup>
<PackageReference Include="Syncfusion.DocIORenderer.Net.Core" Version="*" />
<PackageReference Include="Syncfusion.PdfToImageConverter.Net" Version="*" />
<PackageReference Include="System.Drawing.Common" Version="*" />
</ItemGroup>
<ItemGroup>
<None Update="Data\Input.docx">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="Output\.gitkeep">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
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,55 @@
using Syncfusion.DocIO;
using Syncfusion.DocIO.DLS;
using Syncfusion.DocIORenderer;
using Syncfusion.Pdf;
using System.Drawing;
using Syncfusion.PdfToImageConverter;

namespace Convert_Word_document_to_PDF
{
class Program
{
static void Main(string[] args)
{
//Open the Word document file stream.
using (FileStream fileStream = new FileStream(Path.GetFullPath(@"Data/Input.docx"), FileMode.Open))
{
//Loads an existing Word document.
using (WordDocument wordDocument = new WordDocument(fileStream, FormatType.Automatic))
{
//Creates an instance of DocIORenderer.
using (DocIORenderer renderer = new DocIORenderer())
{
//Converts Word document into PDF document.
using (PdfDocument pdfDocument = renderer.ConvertToPDF(wordDocument))
{
// Save PDF to memory stream
using MemoryStream pdfStream = new MemoryStream();
pdfDocument.Save(pdfStream);
pdfStream.Position = 0;
//Initialize PDF image converter
PdfToImageConverter imageConverter = new PdfToImageConverter();
//Load the PDF document
imageConverter.Load(pdfStream);
//Convert first page of PDF to image (thumbnail)
Stream thumbnailStream = imageConverter.Convert(0, false, false);
//Reset stream position
thumbnailStream.Position = 0;

//Resize image to thumbnail size.
Image image = Image.FromStream(thumbnailStream);
Image thumbnail = image.GetThumbnailImage(600, 700, () => false, IntPtr.Zero);

//Save the image.
thumbnail.Save(Path.GetFullPath(@"Output/Image.png"), System.Drawing.Imaging.ImageFormat.Png);
thumbnail.Dispose();
thumbnailStream.Dispose();
//Close the PDF document
pdfDocument.Close();
}
}
}
}
}
}
}