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

Convert-5-pages-in-Word-to-PDF #210

Merged
merged 3 commits into from
Aug 14, 2024
Merged
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.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,26 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2"/>
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Syncfusion.DocIO.Base" publicKeyToken="3d67ed1f87d44c89" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-26.2462.9.0" newVersion="26.2462.9.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Syncfusion.Pdf.Base" publicKeyToken="3d67ed1f87d44c89" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-26.2462.9.0" newVersion="26.2462.9.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Syncfusion.Compression.Base" publicKeyToken="3d67ed1f87d44c89" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-26.2462.9.0" newVersion="26.2462.9.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Syncfusion.OfficeChart.Base" publicKeyToken="3d67ed1f87d44c89" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-26.2462.9.0" newVersion="26.2462.9.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?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.6.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
<TargetFrameworkProfile />
</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.1462.42.0, Culture=neutral, PublicKeyToken=3d67ed1f87d44c89, processorArchitecture=MSIL">
<HintPath>..\packages\Syncfusion.DocToPDFConverter.WinForms.26.1.42\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,61 @@
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 and save it to a MemoryStream
using (MemoryStream pdfStream = new MemoryStream())
{
using (PdfDocument pdfDocument = render.ConvertToPDF(document))
{
// Save the PDF document to the MemoryStream
pdfDocument.Save(pdfStream);
pdfStream.Position = 0; // Reset the stream position to the beginning

// Load the PDF document from the MemoryStream
using (PdfLoadedDocument loadedDocument = new PdfLoadedDocument(pdfStream))
{
// 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.Write))
{
// 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.1.42" 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>
Loading