-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6c68473
commit 1d2015b
Showing
7 changed files
with
212 additions
and
0 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
...nversion/Convert-5-pages-in-Word-to-PDF/.NET-Framework/Convert-5-pages-in-Word-to-PDF.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,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 |
6 changes: 6 additions & 0 deletions
6
...n/Convert-5-pages-in-Word-to-PDF/.NET-Framework/Convert-5-pages-in-Word-to-PDF/App.config
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,6 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<configuration> | ||
<startup> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" /> | ||
</startup> | ||
</configuration> |
72 changes: 72 additions & 0 deletions
72
...o-PDF/.NET-Framework/Convert-5-pages-in-Word-to-PDF/Convert-5-pages-in-Word-to-PDF.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,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 added
BIN
+157 KB
...vert-5-pages-in-Word-to-PDF/.NET-Framework/Convert-5-pages-in-Word-to-PDF/Data/Input.docx
Binary file not shown.
64 changes: 64 additions & 0 deletions
64
...n/Convert-5-pages-in-Word-to-PDF/.NET-Framework/Convert-5-pages-in-Word-to-PDF/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,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); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...s-in-Word-to-PDF/.NET-Framework/Convert-5-pages-in-Word-to-PDF/Properties/AssemblyInfo.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,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")] |
9 changes: 9 additions & 0 deletions
9
...vert-5-pages-in-Word-to-PDF/.NET-Framework/Convert-5-pages-in-Word-to-PDF/packages.config
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,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> |