diff --git a/Word-to-PDF-Conversion/Convert-5-pages-in-Word-to-PDF/.NET-Framework/Convert-5-pages-in-Word-to-PDF.sln b/Word-to-PDF-Conversion/Convert-5-pages-in-Word-to-PDF/.NET-Framework/Convert-5-pages-in-Word-to-PDF.sln new file mode 100644 index 00000000..ebeb44ec --- /dev/null +++ b/Word-to-PDF-Conversion/Convert-5-pages-in-Word-to-PDF/.NET-Framework/Convert-5-pages-in-Word-to-PDF.sln @@ -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 diff --git a/Word-to-PDF-Conversion/Convert-5-pages-in-Word-to-PDF/.NET-Framework/Convert-5-pages-in-Word-to-PDF/App.config b/Word-to-PDF-Conversion/Convert-5-pages-in-Word-to-PDF/.NET-Framework/Convert-5-pages-in-Word-to-PDF/App.config new file mode 100644 index 00000000..193aecc6 --- /dev/null +++ b/Word-to-PDF-Conversion/Convert-5-pages-in-Word-to-PDF/.NET-Framework/Convert-5-pages-in-Word-to-PDF/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Word-to-PDF-Conversion/Convert-5-pages-in-Word-to-PDF/.NET-Framework/Convert-5-pages-in-Word-to-PDF/Convert-5-pages-in-Word-to-PDF.csproj b/Word-to-PDF-Conversion/Convert-5-pages-in-Word-to-PDF/.NET-Framework/Convert-5-pages-in-Word-to-PDF/Convert-5-pages-in-Word-to-PDF.csproj new file mode 100644 index 00000000..e80cb7a3 --- /dev/null +++ b/Word-to-PDF-Conversion/Convert-5-pages-in-Word-to-PDF/.NET-Framework/Convert-5-pages-in-Word-to-PDF/Convert-5-pages-in-Word-to-PDF.csproj @@ -0,0 +1,72 @@ + + + + + Debug + AnyCPU + {EC0E3D2F-E1CF-4A77-9448-5C871139C469} + Exe + Convert_5_pages_in_Word_to_PDF + Convert-5-pages-in-Word-to-PDF + v4.8 + 512 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\Syncfusion.Compression.Base.26.2.9\lib\net462\Syncfusion.Compression.Base.dll + + + ..\packages\Syncfusion.DocIO.WinForms.26.2.9\lib\net462\Syncfusion.DocIO.Base.dll + + + ..\packages\Syncfusion.DocToPDFConverter.WinForms.26.2.9\lib\net462\Syncfusion.DocToPdfConverter.Base.dll + + + ..\packages\Syncfusion.Licensing.26.2.9\lib\net462\Syncfusion.Licensing.dll + + + ..\packages\Syncfusion.OfficeChart.Base.26.2.9\lib\net462\Syncfusion.OfficeChart.Base.dll + + + ..\packages\Syncfusion.Pdf.WinForms.26.2.9\lib\net462\Syncfusion.Pdf.Base.dll + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Word-to-PDF-Conversion/Convert-5-pages-in-Word-to-PDF/.NET-Framework/Convert-5-pages-in-Word-to-PDF/Data/Input.docx b/Word-to-PDF-Conversion/Convert-5-pages-in-Word-to-PDF/.NET-Framework/Convert-5-pages-in-Word-to-PDF/Data/Input.docx new file mode 100644 index 00000000..46bca5bc Binary files /dev/null and b/Word-to-PDF-Conversion/Convert-5-pages-in-Word-to-PDF/.NET-Framework/Convert-5-pages-in-Word-to-PDF/Data/Input.docx differ diff --git a/Word-to-PDF-Conversion/Convert-5-pages-in-Word-to-PDF/.NET-Framework/Convert-5-pages-in-Word-to-PDF/Program.cs b/Word-to-PDF-Conversion/Convert-5-pages-in-Word-to-PDF/.NET-Framework/Convert-5-pages-in-Word-to-PDF/Program.cs new file mode 100644 index 00000000..b63edbf4 --- /dev/null +++ b/Word-to-PDF-Conversion/Convert-5-pages-in-Word-to-PDF/.NET-Framework/Convert-5-pages-in-Word-to-PDF/Program.cs @@ -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); + } + } + } + } + } +} diff --git a/Word-to-PDF-Conversion/Convert-5-pages-in-Word-to-PDF/.NET-Framework/Convert-5-pages-in-Word-to-PDF/Properties/AssemblyInfo.cs b/Word-to-PDF-Conversion/Convert-5-pages-in-Word-to-PDF/.NET-Framework/Convert-5-pages-in-Word-to-PDF/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..b1e52d4d --- /dev/null +++ b/Word-to-PDF-Conversion/Convert-5-pages-in-Word-to-PDF/.NET-Framework/Convert-5-pages-in-Word-to-PDF/Properties/AssemblyInfo.cs @@ -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")] diff --git a/Word-to-PDF-Conversion/Convert-5-pages-in-Word-to-PDF/.NET-Framework/Convert-5-pages-in-Word-to-PDF/packages.config b/Word-to-PDF-Conversion/Convert-5-pages-in-Word-to-PDF/.NET-Framework/Convert-5-pages-in-Word-to-PDF/packages.config new file mode 100644 index 00000000..c874778c --- /dev/null +++ b/Word-to-PDF-Conversion/Convert-5-pages-in-Word-to-PDF/.NET-Framework/Convert-5-pages-in-Word-to-PDF/packages.config @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file