Skip to content

Commit

Permalink
Convert-5-pages-in-Word-to-PDF
Browse files Browse the repository at this point in the history
  • Loading branch information
DharanyaSakthivel-SF4210 committed Aug 14, 2024
1 parent 6c68473 commit 1d2015b
Show file tree
Hide file tree
Showing 7 changed files with 212 additions and 0 deletions.
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.9.34622.214
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Convert-5-pages-in-Word-to-PDF", "Convert-5-pages-in-Word-to-PDF\Convert-5-pages-in-Word-to-PDF.csproj", "{EC0E3D2F-E1CF-4A77-9448-5C871139C469}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{EC0E3D2F-E1CF-4A77-9448-5C871139C469}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EC0E3D2F-E1CF-4A77-9448-5C871139C469}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EC0E3D2F-E1CF-4A77-9448-5C871139C469}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EC0E3D2F-E1CF-4A77-9448-5C871139C469}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {E4E72D03-F028-4E31-A543-F521F8FC2D91}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
</startup>
</configuration>
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{EC0E3D2F-E1CF-4A77-9448-5C871139C469}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>Convert_5_pages_in_Word_to_PDF</RootNamespace>
<AssemblyName>Convert-5-pages-in-Word-to-PDF</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Syncfusion.Compression.Base, Version=26.2462.9.0, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89, processorArchitecture=MSIL">
<HintPath>..\packages\Syncfusion.Compression.Base.26.2.9\lib\net462\Syncfusion.Compression.Base.dll</HintPath>
</Reference>
<Reference Include="Syncfusion.DocIO.Base, Version=26.2462.9.0, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89, processorArchitecture=MSIL">
<HintPath>..\packages\Syncfusion.DocIO.WinForms.26.2.9\lib\net462\Syncfusion.DocIO.Base.dll</HintPath>
</Reference>
<Reference Include="Syncfusion.DocToPdfConverter.Base, Version=26.2462.9.0, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89, processorArchitecture=MSIL">
<HintPath>..\packages\Syncfusion.DocToPDFConverter.WinForms.26.2.9\lib\net462\Syncfusion.DocToPdfConverter.Base.dll</HintPath>
</Reference>
<Reference Include="Syncfusion.Licensing, Version=26.2462.9.0, Culture=neutral, PublicKeyToken=632609b4d040f6b4, processorArchitecture=MSIL">
<HintPath>..\packages\Syncfusion.Licensing.26.2.9\lib\net462\Syncfusion.Licensing.dll</HintPath>
</Reference>
<Reference Include="Syncfusion.OfficeChart.Base, Version=26.2462.9.0, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89, processorArchitecture=MSIL">
<HintPath>..\packages\Syncfusion.OfficeChart.Base.26.2.9\lib\net462\Syncfusion.OfficeChart.Base.dll</HintPath>
</Reference>
<Reference Include="Syncfusion.Pdf.Base, Version=26.2462.9.0, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89, processorArchitecture=MSIL">
<HintPath>..\packages\Syncfusion.Pdf.WinForms.26.2.9\lib\net462\Syncfusion.Pdf.Base.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using Syncfusion.DocIO.DLS;
using Syncfusion.DocIO;
using System.IO;
using Syncfusion.DocToPDFConverter;
using Syncfusion.Pdf;
using Syncfusion.Pdf.Parsing;

namespace Convert_5_pages_in_Word_to_PDF
{
internal class Program
{
static void Main(string[] args)
{
// Open the input Word document
using (FileStream docStream = new FileStream(Path.GetFullPath(@"../../Data/Input.docx"), FileMode.Open, FileAccess.Read))
{
// Load the Word document
using (WordDocument document = new WordDocument(docStream, FormatType.Docx))
{
// Create a converter to convert the Word document to PDF
using (DocToPDFConverter render = new DocToPDFConverter())
{
// Convert the Word document to a PDF document
using (PdfDocument pdfDocument = render.ConvertToPDF(document))
{
// Create a file stream to save the converted PDF
using (FileStream docStream1 = new FileStream(Path.GetFullPath(@"../../Data/Output.pdf"), FileMode.Create, FileAccess.Write))
{
// Save the PDF document to the output file stream
pdfDocument.Save(docStream1);
}
}
}
}
}

// Get stream from the newly created PDF document
using (FileStream inputFileStream = new FileStream(Path.GetFullPath(@"../../Data/Output.pdf"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
// Load the PDF document
using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputFileStream))
{
// Get the total number of pages in the PDF document
int totalPages = loadedDocument.Pages.Count;
if (totalPages > 5)
{
// Remove all pages after the 5th page
for (int i = totalPages - 1; i >= 5; i--)
{
loadedDocument.Pages.RemoveAt(i);
}
}

// Create a file stream to save the modified PDF
using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"../../Data/First-5-pages-Output.pdf"), FileMode.Create, FileAccess.ReadWrite))
{
// Save the modified PDF document to the output file stream
loadedDocument.Save(outputFileStream);
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Convert-5-pages-in-Word-to-PDF")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Convert-5-pages-in-Word-to-PDF")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("ec0e3d2f-e1cf-4a77-9448-5c871139c469")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Syncfusion.Compression.Base" version="26.2.9" targetFramework="net48" />
<package id="Syncfusion.DocIO.WinForms" version="26.2.9" targetFramework="net48" />
<package id="Syncfusion.DocToPDFConverter.WinForms" version="26.2.9" targetFramework="net48" />
<package id="Syncfusion.Licensing" version="26.2.9" targetFramework="net48" />
<package id="Syncfusion.OfficeChart.Base" version="26.2.9" targetFramework="net48" />
<package id="Syncfusion.Pdf.WinForms" version="26.2.9" targetFramework="net48" />
</packages>

0 comments on commit 1d2015b

Please sign in to comment.