diff --git a/PPTX-to-Image-conversion/Convert-PowerPoint-presentation-to-Image/.NET/Convert-PowerPoint-presentation-to-Image/Program.cs b/PPTX-to-Image-conversion/Convert-PowerPoint-presentation-to-Image/.NET/Convert-PowerPoint-presentation-to-Image/Program.cs index 994033f9..8ab5b59f 100644 --- a/PPTX-to-Image-conversion/Convert-PowerPoint-presentation-to-Image/.NET/Convert-PowerPoint-presentation-to-Image/Program.cs +++ b/PPTX-to-Image-conversion/Convert-PowerPoint-presentation-to-Image/.NET/Convert-PowerPoint-presentation-to-Image/Program.cs @@ -8,26 +8,22 @@ internal class Program { static void Main(string[] args) { - //Open the file as Stream. - using (FileStream fileStream = new FileStream(Path.GetFullPath(@"Data/Template.pptx"), FileMode.Open, FileAccess.Read)) + //Open the existing PowerPoint presentation. + using (IPresentation pptxDoc = Presentation.Open(@"Data/Template.pptx")) { - //Open the existing PowerPoint presentation. - using (IPresentation pptxDoc = Presentation.Open(fileStream)) + //Initialize the PresentationRenderer to perform image conversion. + pptxDoc.PresentationRenderer = new PresentationRenderer(); + //Convert PowerPoint slide to image as stream. + Stream[] images = pptxDoc.RenderAsImages(ExportImageFormat.Jpeg); + //Save the images to file. + for (int i = 0; i < images.Length; i++) { - //Initialize PresentationRenderer. - pptxDoc.PresentationRenderer = new PresentationRenderer(); - //Convert PowerPoint to image as stream. - Stream[] images = pptxDoc.RenderAsImages(ExportImageFormat.Jpeg); - //Save the images to file. - for (int i = 0; i < images.Length; i++) + using (Stream stream = images[i]) { - using (Stream stream = images[i]) + //Save the image stream to a file. + using (FileStream fileStreamOutput = File.Create(Path.GetFullPath("Output/Image" + i + ".jpg"))) { - //Save the image stream to a file. - using (FileStream fileStreamOutput = File.Create(Path.GetFullPath("Output/Image" + i + ".jpg"))) - { - stream.CopyTo(fileStreamOutput); - } + stream.CopyTo(fileStreamOutput); } } } diff --git a/PPTX-to-Image-conversion/Convert-PowerPoint-presentation-to-Image/ASP.NET-Core/Convert-PowerPoint-Presentation-to-Image/Controllers/HomeController.cs b/PPTX-to-Image-conversion/Convert-PowerPoint-presentation-to-Image/ASP.NET-Core/Convert-PowerPoint-Presentation-to-Image/Controllers/HomeController.cs index 712e7e6b..482ec6b8 100644 --- a/PPTX-to-Image-conversion/Convert-PowerPoint-presentation-to-Image/ASP.NET-Core/Convert-PowerPoint-Presentation-to-Image/Controllers/HomeController.cs +++ b/PPTX-to-Image-conversion/Convert-PowerPoint-presentation-to-Image/ASP.NET-Core/Convert-PowerPoint-Presentation-to-Image/Controllers/HomeController.cs @@ -28,22 +28,18 @@ public IActionResult Index() /// public ActionResult ConvertPPTXtoImage(string button) { - //Open the file as Stream. - using (FileStream fileStream = new FileStream(Path.GetFullPath("Data/Input.pptx"), FileMode.Open, FileAccess.Read)) + //Open an existing PowerPoint presentation. + using (IPresentation pptxDoc = Presentation.Open("Data/Input.pptx")) { - //Open the existing PowerPoint presentation. - using (IPresentation pptxDoc = Presentation.Open(fileStream)) - { - //Initialize the PresentationRenderer to perform image conversion. - pptxDoc.PresentationRenderer = new PresentationRenderer(); - //Convert PowerPoint slide to image as stream. - Stream stream = pptxDoc.Slides[0].ConvertToImage(ExportImageFormat.Jpeg); - //Reset the stream position. - stream.Position = 0; - //Download image in the browser. - return File(stream, "application/jpeg", "PPTXtoImage.Jpeg"); - } - } + //Initialize the PresentationRenderer to perform image conversion. + pptxDoc.PresentationRenderer = new PresentationRenderer(); + //Convert PowerPoint slide to image as stream. + Stream stream = pptxDoc.Slides[0].ConvertToImage(ExportImageFormat.Jpeg); + //Reset the stream position. + stream.Position = 0; + //Download image in the browser. + return File(stream, "application/jpeg", "PPTXtoImage.Jpeg"); + } } public IActionResult Privacy() diff --git a/PPTX-to-Image-conversion/Convert-PowerPoint-presentation-to-Image/ASP.NET-MVC/Convert-PowerPoint-Presentation-to-Image/Controllers/HomeController.cs b/PPTX-to-Image-conversion/Convert-PowerPoint-presentation-to-Image/ASP.NET-MVC/Convert-PowerPoint-Presentation-to-Image/Controllers/HomeController.cs index eeadc3b3..65035089 100644 --- a/PPTX-to-Image-conversion/Convert-PowerPoint-presentation-to-Image/ASP.NET-MVC/Convert-PowerPoint-Presentation-to-Image/Controllers/HomeController.cs +++ b/PPTX-to-Image-conversion/Convert-PowerPoint-presentation-to-Image/ASP.NET-MVC/Convert-PowerPoint-Presentation-to-Image/Controllers/HomeController.cs @@ -18,19 +18,13 @@ public ActionResult Index() } public void ConvertPPTXtoImage() { - //Open the file as Stream. - using (FileStream pathStream = new FileStream(Server.MapPath("~/App_Data/Input.pptx"), FileMode.Open, FileAccess.Read)) + // Opens a PowerPoint Presentation. + using (IPresentation pptxDoc = Presentation.Open(Server.MapPath("~/App_Data/Input.pptx"))) { - //Opens a PowerPoint Presentation. - using (IPresentation pptxDoc = Presentation.Open(pathStream)) - { - //Convert the first slide into image. - Image image = pptxDoc.Slides[0].ConvertToImage(Syncfusion.Drawing.ImageType.Metafile); - //Saves the image file to MemoryStream. - MemoryStream stream = new MemoryStream(); - //Download image file in the browser. - ExportAsImage(image, "PPTXToImage.Jpeg", ImageFormat.Jpeg, HttpContext.ApplicationInstance.Response); - } + //Convert the first slide into image. + Image image = pptxDoc.Slides[0].ConvertToImage(Syncfusion.Drawing.ImageType.Metafile); + //Download image file in the browser. + ExportAsImage(image, "PPTXToImage.Jpeg", ImageFormat.Jpeg, HttpContext.ApplicationInstance.Response); } } //To download the image file. diff --git a/PPTX-to-Image-conversion/Convert-PowerPoint-presentation-to-Image/Blazor/Web-Server-App/Convert-PPTX-to-Image/Data/PowerPointService.cs b/PPTX-to-Image-conversion/Convert-PowerPoint-presentation-to-Image/Blazor/Web-Server-App/Convert-PPTX-to-Image/Data/PowerPointService.cs index 2e8ebd04..c7892408 100644 --- a/PPTX-to-Image-conversion/Convert-PowerPoint-presentation-to-Image/Blazor/Web-Server-App/Convert-PPTX-to-Image/Data/PowerPointService.cs +++ b/PPTX-to-Image-conversion/Convert-PowerPoint-presentation-to-Image/Blazor/Web-Server-App/Convert-PPTX-to-Image/Data/PowerPointService.cs @@ -9,26 +9,22 @@ public class PowerPointService { public MemoryStream ConvertPPTXtoImage() { - //Open the file as Stream. - using (FileStream sourceStreamPath = new FileStream(@"wwwroot/Input.pptx", FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) + //Opens an existing PowerPoint presentation from the wwwroot folder. + using (IPresentation pptxDoc = Presentation.Open(Path.Combine("wwwroot", "Input.pptx"))) { - //Open the existing PowerPoint presentation with loaded stream. - using (IPresentation pptxDoc = Presentation.Open(sourceStreamPath)) + //Initialize the PresentationRenderer to perform image conversion. + pptxDoc.PresentationRenderer = new PresentationRenderer(); + //Convert PowerPoint slide to image as stream. + using (Stream stream = pptxDoc.Slides[0].ConvertToImage(ExportImageFormat.Jpeg)) { - //Initialize the PresentationRenderer to perform image conversion. - pptxDoc.PresentationRenderer = new PresentationRenderer(); - //Convert PowerPoint slide to image as stream. - using (Stream stream = pptxDoc.Slides[0].ConvertToImage(ExportImageFormat.Jpeg)) - { - //Save the converted image file to MemoryStream. - MemoryStream Stream = new MemoryStream(); - stream.CopyTo(Stream); - Stream.Position = 0; - //Download image file in the browser. - return Stream; - } + //Save the converted image file to MemoryStream. + MemoryStream outputStream = new MemoryStream(); + stream.CopyTo(outputStream); + outputStream.Position = 0; + //Return the image stream for download in the browser. + return outputStream; } - } + } } } } \ No newline at end of file diff --git a/PPTX-to-Image-conversion/Convert-PowerPoint-presentation-to-Image/GCP/Google_App_Engine/Convert-PPTX-to-image/Controllers/HomeController.cs b/PPTX-to-Image-conversion/Convert-PowerPoint-presentation-to-Image/GCP/Google_App_Engine/Convert-PPTX-to-image/Controllers/HomeController.cs index 0924bf82..a839aec5 100644 --- a/PPTX-to-Image-conversion/Convert-PowerPoint-presentation-to-Image/GCP/Google_App_Engine/Convert-PPTX-to-image/Controllers/HomeController.cs +++ b/PPTX-to-Image-conversion/Convert-PowerPoint-presentation-to-Image/GCP/Google_App_Engine/Convert-PPTX-to-image/Controllers/HomeController.cs @@ -20,19 +20,17 @@ public ActionResult ConvertPPTXToImage() MemoryStream stream = new MemoryStream(); try { - using (FileStream inputStream = new FileStream(Path.GetFullPath("Data/Input.pptx"), FileMode.Open, FileAccess.Read)) + //Open the existing PPTX document. + using (IPresentation pptxDoc = Presentation.Open(Path.GetFullPath("Data/Input.pptx"))) { - //Opens the existing PPTX document. - using (IPresentation pptxDoc = Presentation.Open(inputStream)) - { - //Initialize the PresentationRenderer to perform image conversion. - pptxDoc.PresentationRenderer = new PresentationRenderer(); - //Convert PowerPoint slide to image as stream. - stream = (MemoryStream)pptxDoc.Slides[0].ConvertToImage(ExportImageFormat.Jpeg); - } + //Initialize the PresentationRenderer to perform image conversion. + pptxDoc.PresentationRenderer = new PresentationRenderer(); + //Convert PowerPoint slide to image as stream. + stream = (MemoryStream)pptxDoc.Slides[0].ConvertToImage(ExportImageFormat.Jpeg); + stream.Position = 0; + //Download image file in the browser. + return File(stream, "image/jpeg", "PPTXToimage_Page1.jpeg"); } - //Download image in the browser. - return File(stream, "image/jpeg", "PPTXToimage_Page1.jpeg"); } catch (Exception ex) { diff --git a/PPTX-to-Image-conversion/Convert-PowerPoint-presentation-to-Image/Linux/Convert-PowerPoint-Presentation-to-Image/Convert-PowerPoint-Presentation-to-Image.csproj b/PPTX-to-Image-conversion/Convert-PowerPoint-presentation-to-Image/Linux/Convert-PowerPoint-Presentation-to-Image/Convert-PowerPoint-Presentation-to-Image.csproj index 7a129848..a503c79a 100644 --- a/PPTX-to-Image-conversion/Convert-PowerPoint-presentation-to-Image/Linux/Convert-PowerPoint-Presentation-to-Image/Convert-PowerPoint-Presentation-to-Image.csproj +++ b/PPTX-to-Image-conversion/Convert-PowerPoint-presentation-to-Image/Linux/Convert-PowerPoint-Presentation-to-Image/Convert-PowerPoint-Presentation-to-Image.csproj @@ -13,4 +13,11 @@ + + + + Always + + + diff --git a/PPTX-to-Image-conversion/Convert-PowerPoint-presentation-to-Image/Linux/Convert-PowerPoint-Presentation-to-Image/Program.cs b/PPTX-to-Image-conversion/Convert-PowerPoint-presentation-to-Image/Linux/Convert-PowerPoint-Presentation-to-Image/Program.cs index 6b327461..c9664462 100644 --- a/PPTX-to-Image-conversion/Convert-PowerPoint-presentation-to-Image/Linux/Convert-PowerPoint-Presentation-to-Image/Program.cs +++ b/PPTX-to-Image-conversion/Convert-PowerPoint-presentation-to-Image/Linux/Convert-PowerPoint-Presentation-to-Image/Program.cs @@ -11,25 +11,21 @@ class Program { static void Main(string[] args) { - //Open the file as Stream. - using (FileStream fileStreamInput = new FileStream(Path.GetFullPath(@"Data/Input.pptx"), FileMode.Open, FileAccess.Read)) + //Open the existing PowerPoint presentation. + using (IPresentation pptxDoc = Presentation.Open("Data/Input.pptx")) { - //Open the existing PowerPoint presentation with loaded stream. - using (IPresentation pptxDoc = Presentation.Open(fileStreamInput)) + //Initialize the PresentationRenderer to perform image conversion. + pptxDoc.PresentationRenderer = new PresentationRenderer(); + //Convert PowerPoint slide to image as stream. + using (Stream stream = pptxDoc.Slides[0].ConvertToImage(ExportImageFormat.Jpeg)) { - //Initialize the PresentationRenderer to perform image conversion. - pptxDoc.PresentationRenderer = new PresentationRenderer(); - //Convert PowerPoint slide to image as stream. - using (Stream stream = pptxDoc.Slides[0].ConvertToImage(ExportImageFormat.Jpeg)) + //Reset the stream position. + stream.Position = 0; + //Create FileStream to save the image file. + using (FileStream outputStream = new FileStream("PPTXtoImage.Jpeg", FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite)) { - //Reset the stream position. - stream.Position = 0; - //Create FileStream to save the image file. - using (FileStream outputStream = new FileStream("PPTXtoImage.Jpeg", FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite)) - { - //Save the image file. - stream.CopyTo(outputStream); - } + //Save the image file. + stream.CopyTo(outputStream); } } } diff --git a/PPTX-to-Image-conversion/Convert-PowerPoint-presentation-to-Image/MAC/Convert-PowerPoint-Presentation-to-Image/Convert-PowerPoint-Presentation-to-Image.csproj b/PPTX-to-Image-conversion/Convert-PowerPoint-presentation-to-Image/MAC/Convert-PowerPoint-Presentation-to-Image/Convert-PowerPoint-Presentation-to-Image.csproj index 2b93b781..74b31d50 100644 --- a/PPTX-to-Image-conversion/Convert-PowerPoint-presentation-to-Image/MAC/Convert-PowerPoint-Presentation-to-Image/Convert-PowerPoint-Presentation-to-Image.csproj +++ b/PPTX-to-Image-conversion/Convert-PowerPoint-presentation-to-Image/MAC/Convert-PowerPoint-Presentation-to-Image/Convert-PowerPoint-Presentation-to-Image.csproj @@ -11,4 +11,11 @@ + + + + Always + + + diff --git a/PPTX-to-Image-conversion/Convert-PowerPoint-presentation-to-Image/MAC/Convert-PowerPoint-Presentation-to-Image/Program.cs b/PPTX-to-Image-conversion/Convert-PowerPoint-presentation-to-Image/MAC/Convert-PowerPoint-Presentation-to-Image/Program.cs index 4f56af1f..c9664462 100644 --- a/PPTX-to-Image-conversion/Convert-PowerPoint-presentation-to-Image/MAC/Convert-PowerPoint-Presentation-to-Image/Program.cs +++ b/PPTX-to-Image-conversion/Convert-PowerPoint-presentation-to-Image/MAC/Convert-PowerPoint-Presentation-to-Image/Program.cs @@ -11,25 +11,21 @@ class Program { static void Main(string[] args) { - //Open the file as Stream. - using (FileStream fileStreamInput = new FileStream(Path.GetFullPath(@"../../../Data/Input.pptx"), FileMode.Open, FileAccess.Read)) + //Open the existing PowerPoint presentation. + using (IPresentation pptxDoc = Presentation.Open("Data/Input.pptx")) { - //Open the existing PowerPoint presentation with loaded stream. - using (IPresentation pptxDoc = Presentation.Open(fileStreamInput)) + //Initialize the PresentationRenderer to perform image conversion. + pptxDoc.PresentationRenderer = new PresentationRenderer(); + //Convert PowerPoint slide to image as stream. + using (Stream stream = pptxDoc.Slides[0].ConvertToImage(ExportImageFormat.Jpeg)) { - //Initialize the PresentationRenderer to perform image conversion. - pptxDoc.PresentationRenderer = new PresentationRenderer(); - //Convert PowerPoint slide to image as stream. - using (Stream stream = pptxDoc.Slides[0].ConvertToImage(ExportImageFormat.Jpeg)) + //Reset the stream position. + stream.Position = 0; + //Create FileStream to save the image file. + using (FileStream outputStream = new FileStream("PPTXtoImage.Jpeg", FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite)) { - //Reset the stream position. - stream.Position = 0; - //Create FileStream to save the image file. - using (FileStream outputStream = new FileStream("PPTXtoImage.Jpeg", FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite)) - { - //Save the image file. - stream.CopyTo(outputStream); - } + //Save the image file. + stream.CopyTo(outputStream); } } } diff --git a/PPTX-to-Image-conversion/Convert-PowerPoint-slide-to-Image/.NET/Convert-PowerPoint-slide-to-Image/Program.cs b/PPTX-to-Image-conversion/Convert-PowerPoint-slide-to-Image/.NET/Convert-PowerPoint-slide-to-Image/Program.cs index 476695f0..b4f0dd40 100644 --- a/PPTX-to-Image-conversion/Convert-PowerPoint-slide-to-Image/.NET/Convert-PowerPoint-slide-to-Image/Program.cs +++ b/PPTX-to-Image-conversion/Convert-PowerPoint-slide-to-Image/.NET/Convert-PowerPoint-slide-to-Image/Program.cs @@ -1,22 +1,18 @@ using Syncfusion.Presentation; using Syncfusion.PresentationRenderer; -//Open an existing presentation. -using (FileStream inputStream = new(Path.GetFullPath(@"Data/Template.pptx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) +//Open the existing PowerPoint presentation. +using (IPresentation pptxDoc = Presentation.Open(@"Data/Template.pptx")) { - //Load the presentation. - using (IPresentation pptxDoc = Presentation.Open(inputStream)) + //Initialize PresentationRenderer. + pptxDoc.PresentationRenderer = new PresentationRenderer(); + //Convert the PowerPoint slide as an image stream. + using (Stream stream = pptxDoc.Slides[0].ConvertToImage(ExportImageFormat.Jpeg)) { - //Initialize PresentationRenderer. - pptxDoc.PresentationRenderer = new PresentationRenderer(); - //Convert the PowerPoint slide as an image stream. - using (Stream stream = pptxDoc.Slides[0].ConvertToImage(ExportImageFormat.Jpeg)) + //Save the image stream to a file. + using (FileStream fileStreamOutput = File.Create(@"Output/Image.jpg")) { - //Save the image stream to a file. - using (FileStream fileStreamOutput = File.Create(Path.GetFullPath(@"Output/Image.jpg"))) - { - stream.CopyTo(fileStreamOutput); - } - } - } + stream.CopyTo(fileStreamOutput); + } + } } \ No newline at end of file diff --git a/PPTX-to-Image-conversion/Fallback-fonts-based-on-scripttype/.NET/Fallback-fonts-based-on-scripttype/Program.cs b/PPTX-to-Image-conversion/Fallback-fonts-based-on-scripttype/.NET/Fallback-fonts-based-on-scripttype/Program.cs index 911c87a7..bcdd51cd 100644 --- a/PPTX-to-Image-conversion/Fallback-fonts-based-on-scripttype/.NET/Fallback-fonts-based-on-scripttype/Program.cs +++ b/PPTX-to-Image-conversion/Fallback-fonts-based-on-scripttype/.NET/Fallback-fonts-based-on-scripttype/Program.cs @@ -8,34 +8,38 @@ internal class Program { static void Main(string[] args) { - //Load the PowerPoint presentation into stream. - using FileStream fileStreamInput = new FileStream(Path.GetFullPath(@"Data/Template.pptx"), FileMode.Open, FileAccess.Read); - //Open the existing PowerPoint presentation with loaded stream. - using IPresentation pptxDoc = Presentation.Open(fileStreamInput); - //Adds fallback font for "Arabic" script type. - pptxDoc.FontSettings.FallbackFonts.Add(ScriptType.Arabic, "Arial, Times New Roman"); - //Adds fallback font for "Hebrew" script type. - pptxDoc.FontSettings.FallbackFonts.Add(ScriptType.Hebrew, "Arial, Courier New"); - //Adds fallback font for "Hindi" script type. - pptxDoc.FontSettings.FallbackFonts.Add(ScriptType.Hindi, "Mangal, Nirmala UI"); - //Adds fallback font for "Chinese" script type. - pptxDoc.FontSettings.FallbackFonts.Add(ScriptType.Chinese, "DengXian, MingLiU"); - //Adds fallback font for "Japanese" script type. - pptxDoc.FontSettings.FallbackFonts.Add(ScriptType.Japanese, "Yu Mincho, MS Mincho"); - //Adds fallback font for "Thai" script type. - pptxDoc.FontSettings.FallbackFonts.Add(ScriptType.Thai, "Tahoma, Microsoft Sans Serif"); - //Adds fallback font for "Korean" script type. - pptxDoc.FontSettings.FallbackFonts.Add(ScriptType.Korean, "Malgun Gothic, Batang"); - //Initialize the PresentationRenderer to perform image conversion. - pptxDoc.PresentationRenderer = new PresentationRenderer(); - //Convert PowerPoint slide to image as stream. - using Stream stream = pptxDoc.Slides[0].ConvertToImage(ExportImageFormat.Jpeg); - //Reset the stream position. - stream.Position = 0; - //Create the output image file stream. - using FileStream fileStreamOutput = File.Create(Path.GetFullPath(@"Output/Output.jpg")); - //Copy the converted image stream into created output stream. - stream.CopyTo(fileStreamOutput); + //Open the existing PowerPoint presentation. + using (IPresentation pptxDoc = Presentation.Open(@"Data/Template.pptx")) + { + //Adds fallback font for "Arabic" script type. + pptxDoc.FontSettings.FallbackFonts.Add(ScriptType.Arabic, "Arial, Times New Roman"); + //Adds fallback font for "Hebrew" script type. + pptxDoc.FontSettings.FallbackFonts.Add(ScriptType.Hebrew, "Arial, Courier New"); + //Adds fallback font for "Hindi" script type. + pptxDoc.FontSettings.FallbackFonts.Add(ScriptType.Hindi, "Mangal, Nirmala UI"); + //Adds fallback font for "Chinese" script type. + pptxDoc.FontSettings.FallbackFonts.Add(ScriptType.Chinese, "DengXian, MingLiU"); + //Adds fallback font for "Japanese" script type. + pptxDoc.FontSettings.FallbackFonts.Add(ScriptType.Japanese, "Yu Mincho, MS Mincho"); + //Adds fallback font for "Thai" script type. + pptxDoc.FontSettings.FallbackFonts.Add(ScriptType.Thai, "Tahoma, Microsoft Sans Serif"); + //Adds fallback font for "Korean" script type. + pptxDoc.FontSettings.FallbackFonts.Add(ScriptType.Korean, "Malgun Gothic, Batang"); + //Initialize the PresentationRenderer to perform image conversion. + pptxDoc.PresentationRenderer = new PresentationRenderer(); + //Convert PowerPoint slide to image as stream. + using (Stream stream = pptxDoc.Slides[0].ConvertToImage(ExportImageFormat.Jpeg)) + { + //Reset the stream position. + stream.Position = 0; + //Create the output image file stream. + using (FileStream fileStreamOutput = File.Create(@"Output/Output.jpg")) + { + //Copy the converted image stream into created output stream. + stream.CopyTo(fileStreamOutput); + } + } + } } } } diff --git a/PPTX-to-Image-conversion/Fallback-fonts-for-Unicode-range/.NET/Fallback-fonts-for-Unicode-range/Program.cs b/PPTX-to-Image-conversion/Fallback-fonts-for-Unicode-range/.NET/Fallback-fonts-for-Unicode-range/Program.cs index c53731c4..f199b17b 100644 --- a/PPTX-to-Image-conversion/Fallback-fonts-for-Unicode-range/.NET/Fallback-fonts-for-Unicode-range/Program.cs +++ b/PPTX-to-Image-conversion/Fallback-fonts-for-Unicode-range/.NET/Fallback-fonts-for-Unicode-range/Program.cs @@ -2,30 +2,34 @@ using Syncfusion.Presentation; using Syncfusion.PresentationRenderer; -//Load or open an PowerPoint Presentation. -using FileStream inputStream = new(Path.GetFullPath(@"Data/Template.pptx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite); -//Open an existing PowerPoint presentation. -using IPresentation pptxDoc = Presentation.Open(inputStream); -//Adds fallback font for specific unicode range. -// Arabic. -pptxDoc.FontSettings.FallbackFonts.Add(new FallbackFont(0x0600, 0x06ff, "Arial")); -// Hebrew. -pptxDoc.FontSettings.FallbackFonts.Add(new FallbackFont(0x0590, 0x05ff, "Arial")); -// Hindi. -pptxDoc.FontSettings.FallbackFonts.Add(new FallbackFont(0x0900, 0x097F, "Mangal")); -// Chinese. -pptxDoc.FontSettings.FallbackFonts.Add(new FallbackFont(0x4E00, 0x9FFF, "DengXian")); -// Japanese. -pptxDoc.FontSettings.FallbackFonts.Add(new FallbackFont(0x3040, 0x309F, "MS Mincho")); -// Korean. -pptxDoc.FontSettings.FallbackFonts.Add(new FallbackFont(0xAC00, 0xD7A3, "Malgun Gothic")); -//Initialize the PresentationRenderer to perform image conversion. -pptxDoc.PresentationRenderer = new PresentationRenderer(); -//Convert PowerPoint slide to image as stream. -Stream stream = pptxDoc.Slides[0].ConvertToImage(ExportImageFormat.Jpeg); -//Reset the stream position. -stream.Position = 0; -//Create the output image file stream. -using FileStream fileStreamOutput = File.Create(Path.GetFullPath("Output/Output.jpg")); -//Copy the converted image stream into created output stream. -stream.CopyTo(fileStreamOutput); \ No newline at end of file +//Open the existing PowerPoint presentation. +using (IPresentation pptxDoc = Presentation.Open(@"Data/Template.pptx")) +{ + //Adds fallback font for specific unicode range. + // Arabic. + pptxDoc.FontSettings.FallbackFonts.Add(new FallbackFont(0x0600, 0x06ff, "Arial")); + // Hebrew. + pptxDoc.FontSettings.FallbackFonts.Add(new FallbackFont(0x0590, 0x05ff, "Arial")); + // Hindi. + pptxDoc.FontSettings.FallbackFonts.Add(new FallbackFont(0x0900, 0x097F, "Mangal")); + // Chinese. + pptxDoc.FontSettings.FallbackFonts.Add(new FallbackFont(0x4E00, 0x9FFF, "DengXian")); + // Japanese. + pptxDoc.FontSettings.FallbackFonts.Add(new FallbackFont(0x3040, 0x309F, "MS Mincho")); + // Korean. + pptxDoc.FontSettings.FallbackFonts.Add(new FallbackFont(0xAC00, 0xD7A3, "Malgun Gothic")); + //Initialize the PresentationRenderer to perform image conversion. + pptxDoc.PresentationRenderer = new PresentationRenderer(); + //Convert PowerPoint slide to image as stream. + using (Stream stream = pptxDoc.Slides[0].ConvertToImage(ExportImageFormat.Jpeg)) + { + //Reset the stream position. + stream.Position = 0; + //Create the output image file stream. + using (FileStream fileStreamOutput = File.Create("Output/Output.jpg")) + { + //Copy the converted image stream into created output stream. + stream.CopyTo(fileStreamOutput); + } + } +} \ No newline at end of file diff --git a/PPTX-to-Image-conversion/Fallback-symbols-based-on-scripttype/.NET/Fallback-symbols-based-on-scripttype/Program.cs b/PPTX-to-Image-conversion/Fallback-symbols-based-on-scripttype/.NET/Fallback-symbols-based-on-scripttype/Program.cs index 5a2b27bb..0b9e3b23 100644 --- a/PPTX-to-Image-conversion/Fallback-symbols-based-on-scripttype/.NET/Fallback-symbols-based-on-scripttype/Program.cs +++ b/PPTX-to-Image-conversion/Fallback-symbols-based-on-scripttype/.NET/Fallback-symbols-based-on-scripttype/Program.cs @@ -8,26 +8,30 @@ internal class Program { static void Main(string[] args) { - //Load the PowerPoint presentation into stream. - using FileStream fileStreamInput = new FileStream(Path.GetFullPath(@"Data/Template.pptx"), FileMode.Open, FileAccess.Read); - //Open the existing PowerPoint presentation with loaded stream. - using IPresentation pptxDoc = Presentation.Open(fileStreamInput); - //Adds fallback font for basic symbols like bullet characters. - pptxDoc.FontSettings.FallbackFonts.Add(ScriptType.Symbols, "Segoe UI Symbol, Arial Unicode MS, Wingdings"); - //Adds fallback font for mathematics symbols. - pptxDoc.FontSettings.FallbackFonts.Add(ScriptType.Mathematics, "Cambria Math, Noto Sans Math, Segoe UI Symbol, Arial Unicode MS"); - //Adds fallback font for emojis. - pptxDoc.FontSettings.FallbackFonts.Add(ScriptType.Emoji, "Segoe UI Emoji, Noto Color Emoji, Arial Unicode MS"); - //Initialize the PresentationRenderer to perform image conversion. - pptxDoc.PresentationRenderer = new PresentationRenderer(); - //Convert PowerPoint slide to image as stream. - using Stream stream = pptxDoc.Slides[0].ConvertToImage(ExportImageFormat.Jpeg); - //Reset the stream position. - stream.Position = 0; - //Create the output image file stream. - using FileStream fileStreamOutput = File.Create(Path.GetFullPath(@"../../../Output/Output.jpg")); - //Copy the converted image stream into created output stream. - stream.CopyTo(fileStreamOutput); + //Open the existing PowerPoint presentation. + using (IPresentation pptxDoc = Presentation.Open(@"Data/Template.pptx")) + { + //Adds fallback font for basic symbols like bullet characters. + pptxDoc.FontSettings.FallbackFonts.Add(ScriptType.Symbols, "Segoe UI Symbol, Arial Unicode MS, Wingdings"); + //Adds fallback font for mathematics symbols. + pptxDoc.FontSettings.FallbackFonts.Add(ScriptType.Mathematics, "Cambria Math, Noto Sans Math, Segoe UI Symbol, Arial Unicode MS"); + //Adds fallback font for emojis. + pptxDoc.FontSettings.FallbackFonts.Add(ScriptType.Emoji, "Segoe UI Emoji, Noto Color Emoji, Arial Unicode MS"); + //Initialize the PresentationRenderer to perform image conversion. + pptxDoc.PresentationRenderer = new PresentationRenderer(); + //Convert PowerPoint slide to image as stream. + using (Stream stream = pptxDoc.Slides[0].ConvertToImage(ExportImageFormat.Jpeg)) + { + //Reset the stream position. + stream.Position = 0; + //Create the output image file stream. + using (FileStream fileStreamOutput = File.Create(@"../../../Output/Output.jpg")) + { + //Copy the converted image stream into created output stream. + stream.CopyTo(fileStreamOutput); + } + } + } } } } diff --git a/PPTX-to-Image-conversion/Initialize-default-fallback-fonts/.NET/Initialize-default-fallback-fonts/Program.cs b/PPTX-to-Image-conversion/Initialize-default-fallback-fonts/.NET/Initialize-default-fallback-fonts/Program.cs index c9194403..d791efd4 100644 --- a/PPTX-to-Image-conversion/Initialize-default-fallback-fonts/.NET/Initialize-default-fallback-fonts/Program.cs +++ b/PPTX-to-Image-conversion/Initialize-default-fallback-fonts/.NET/Initialize-default-fallback-fonts/Program.cs @@ -1,19 +1,23 @@ using Syncfusion.Presentation; using Syncfusion.PresentationRenderer; -//Load or open an PowerPoint Presentation. -using FileStream inputStream = new(Path.GetFullPath(@"Data/Template.pptx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite); -//Open an existing PowerPoint presentation. -using IPresentation pptxDoc = Presentation.Open(inputStream); -//Initialize the PresentationRenderer to perform image conversion. -pptxDoc.PresentationRenderer = new PresentationRenderer(); -//Use a sets of default FallbackFont collection to IPresentation. -pptxDoc.FontSettings.FallbackFonts.InitializeDefault(); -//Convert PowerPoint slide to image as stream. -using Stream stream = pptxDoc.Slides[0].ConvertToImage(ExportImageFormat.Jpeg); -//Reset the stream position. -stream.Position = 0; -//Create the output image file stream. -using FileStream fileStreamOutput = File.Create(Path.GetFullPath("Output/Output.jpg")); -//Copy the converted image stream into created output stream. -stream.CopyTo(fileStreamOutput); \ No newline at end of file +//Open the existing PowerPoint presentation. +using (IPresentation pptxDoc = Presentation.Open(@"Data/Template.pptx")) +{ + //Initialize the PresentationRenderer to perform image conversion. + pptxDoc.PresentationRenderer = new PresentationRenderer(); + //Use a set of default FallbackFont collections for IPresentation. + pptxDoc.FontSettings.FallbackFonts.InitializeDefault(); + //Convert PowerPoint slide to image as stream. + using (Stream stream = pptxDoc.Slides[0].ConvertToImage(ExportImageFormat.Jpeg)) + { + //Reset the stream position. + stream.Position = 0; + //Create the output image file stream. + using (FileStream fileStreamOutput = File.Create("Output/Output.jpg")) + { + //Copy the converted image stream into created output stream. + stream.CopyTo(fileStreamOutput); + } + } +} \ No newline at end of file diff --git a/PPTX-to-Image-conversion/Modify-the-exiting-fallback-fonts/.NET/Modify-the-exiting-fallback-fonts/Program.cs b/PPTX-to-Image-conversion/Modify-the-exiting-fallback-fonts/.NET/Modify-the-exiting-fallback-fonts/Program.cs index 0f7dfaaf..7b46eebf 100644 --- a/PPTX-to-Image-conversion/Modify-the-exiting-fallback-fonts/.NET/Modify-the-exiting-fallback-fonts/Program.cs +++ b/PPTX-to-Image-conversion/Modify-the-exiting-fallback-fonts/.NET/Modify-the-exiting-fallback-fonts/Program.cs @@ -2,27 +2,31 @@ using Syncfusion.Presentation; using Syncfusion.PresentationRenderer; -//Load or open an PowerPoint Presentation. -using FileStream inputStream = new(Path.GetFullPath(@"Data/Template.pptx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite); -//Open an existing PowerPoint presentation. -using IPresentation pptxDoc = Presentation.Open(inputStream); -//Initialize the PresentationRenderer to perform image conversion. -pptxDoc.PresentationRenderer = new PresentationRenderer(); -//Use a sets of default FallbackFont collection to IPresentation. -pptxDoc.FontSettings.FallbackFonts.InitializeDefault(); -// Customize a default fallback font name. -FallbackFonts fallbackFonts = pptxDoc.FontSettings.FallbackFonts; -foreach (FallbackFont fallbackFont in fallbackFonts) +//Open the existing PowerPoint presentation. +using (IPresentation pptxDoc = Presentation.Open(@"Data/Template.pptx")) { - //Customize a default fallback font name as "David" for the Hebrew script. - if (fallbackFont.ScriptType == ScriptType.Hebrew) - fallbackFont.FontNames = "David"; + //Initialize the PresentationRenderer to perform image conversion. + pptxDoc.PresentationRenderer = new PresentationRenderer(); + //Use a sets of default FallbackFont collection to IPresentation. + pptxDoc.FontSettings.FallbackFonts.InitializeDefault(); + // Customize a default fallback font name. + FallbackFonts fallbackFonts = pptxDoc.FontSettings.FallbackFonts; + foreach (FallbackFont fallbackFont in fallbackFonts) + { + //Customize a default fallback font name as "David" for the Hebrew script. + if (fallbackFont.ScriptType == ScriptType.Hebrew) + fallbackFont.FontNames = "David"; + } + //Convert PowerPoint slide to image as stream. + using (Stream stream = pptxDoc.Slides[0].ConvertToImage(ExportImageFormat.Jpeg)) + { + //Reset the stream position. + stream.Position = 0; + //Create the output image file stream. + using (FileStream fileStreamOutput = File.Create("Output/Output.jpg")) + { + //Copy the converted image stream into created output stream. + stream.CopyTo(fileStreamOutput); + } + } } -//Convert PowerPoint slide to image as stream. -Stream stream = pptxDoc.Slides[0].ConvertToImage(ExportImageFormat.Jpeg); -//Reset the stream position. -stream.Position = 0; -//Create the output image file stream. -using FileStream fileStreamOutput = File.Create(Path.GetFullPath("Output/Output.jpg")); -//Copy the converted image stream into created output stream. -stream.CopyTo(fileStreamOutput); \ No newline at end of file diff --git a/PPTX-to-PDF-conversion/Apply-substitution-font-name/.NET/Apply-substitution-font-name/Program.cs b/PPTX-to-PDF-conversion/Apply-substitution-font-name/.NET/Apply-substitution-font-name/Program.cs index c4ebd7e2..796f08d9 100644 --- a/PPTX-to-PDF-conversion/Apply-substitution-font-name/.NET/Apply-substitution-font-name/Program.cs +++ b/PPTX-to-PDF-conversion/Apply-substitution-font-name/.NET/Apply-substitution-font-name/Program.cs @@ -2,19 +2,20 @@ using Syncfusion.Presentation; using Syncfusion.PresentationRenderer; -//Load or open an PowerPoint Presentation. -using FileStream inputStream = new(Path.GetFullPath(@"Data/Template.pptx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite); -//Open an existing PowerPoint presentation. -using IPresentation pptxDoc = Presentation.Open(inputStream); -// Initialize the 'SubstituteFont' event to set the replacement font. -pptxDoc.FontSettings.SubstituteFont += SubstituteFont; -//Convert the PowerPoint presentation to PDF file. -using PdfDocument pdfDocument = PresentationToPdfConverter.Convert(pptxDoc); -//Create new instance of file stream. -using FileStream pdfStream = new(Path.GetFullPath(@"Output/PPTXToPDF.pdf"), FileMode.Create); -//Save the generated PDF to file stream. -pdfDocument.Save(pdfStream); - +//Load the PowerPoint presentation. +using (IPresentation pptxDoc = Presentation.Open(@"Data/Template.pptx")) +{ + //Initialize the SubstituteFont event to set the replacement font. + pptxDoc.FontSettings.SubstituteFont += SubstituteFont; + //Convert the PowerPoint presentation to PDF document. + using (PdfDocument pdfDocument = PresentationToPdfConverter.Convert(pptxDoc)) + { + //Save the generated PDF to the file system. + pdfDocument.Save(@"Output/PPTXToPDF.pdf"); + //Release all resources. + pdfDocument.Close(true); + } +} /// /// Sets the alternate font when a specified font is unavailable in the production environment. /// diff --git a/PPTX-to-PDF-conversion/Apply-substitution-font-stream/.NET/Apply-substitution-font-stream/Program.cs b/PPTX-to-PDF-conversion/Apply-substitution-font-stream/.NET/Apply-substitution-font-stream/Program.cs index 51c258d4..af9c3110 100644 --- a/PPTX-to-PDF-conversion/Apply-substitution-font-stream/.NET/Apply-substitution-font-stream/Program.cs +++ b/PPTX-to-PDF-conversion/Apply-substitution-font-stream/.NET/Apply-substitution-font-stream/Program.cs @@ -3,25 +3,27 @@ using Syncfusion.Presentation; using Syncfusion.PresentationRenderer; -//Load or open an PowerPoint Presentation. -using FileStream inputStream = new(Path.GetFullPath(@"Data/Template.pptx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite); -//Open an existing PowerPoint presentation. -using IPresentation pptxDoc = Presentation.Open(inputStream); -// Initialize the 'SubstituteFont' event to set the replacement font. -pptxDoc.FontSettings.SubstituteFont += FontSettings_SubstituteFont; -//Convert the PowerPoint presentation to PDF file. -using PdfDocument pdfDocument = PresentationToPdfConverter.Convert(pptxDoc); -//Create new instance of file stream. -using FileStream pdfStream = new(Path.GetFullPath(@"Output/PPTXToPDF.pdf"), FileMode.Create); -//Save the generated PDF to file stream. -pdfDocument.Save(pdfStream); +//Load the PowerPoint presentation. +using (IPresentation pptxDoc = Presentation.Open(@"Data/Template.pptx")) +{ + //Initialize the SubstituteFont event to set the replacement font. + pptxDoc.FontSettings.SubstituteFont += SubstituteFont; + //Convert the PowerPoint presentation to PDF document. + using (PdfDocument pdfDocument = PresentationToPdfConverter.Convert(pptxDoc)) + { + //Save the generated PDF to the file system. + pdfDocument.Save(@"Output/PPTXToPDF.pdf"); + //Release all resources. + pdfDocument.Close(true); + } +} /// /// Sets the alternate font stream when a specified font is unavailable in the production environment. /// /// FontSettings type of the Presentation in which the specified font stream is used but unavailable in production environment. /// Retrieves the unavailable font name and receives the substitute font stream for conversion. -static void FontSettings_SubstituteFont(object sender, SubstituteFontEventArgs args) +static void SubstituteFont(object sender, SubstituteFontEventArgs args) { if (args.OriginalFontName == "Arial" && args.FontStyle == FontStyle.Bold) args.AlternateFontStream = new FileStream(Path.GetFullPath(@"Data/cambriab.ttf"), FileMode.Open); diff --git a/PPTX-to-PDF-conversion/Convert-PowerPoint-into-accessible-PDF/.NET/Convert-PowerPoint-into-accessible-PDF/Program.cs b/PPTX-to-PDF-conversion/Convert-PowerPoint-into-accessible-PDF/.NET/Convert-PowerPoint-into-accessible-PDF/Program.cs index dc914372..cdf8c525 100644 --- a/PPTX-to-PDF-conversion/Convert-PowerPoint-into-accessible-PDF/.NET/Convert-PowerPoint-into-accessible-PDF/Program.cs +++ b/PPTX-to-PDF-conversion/Convert-PowerPoint-into-accessible-PDF/.NET/Convert-PowerPoint-into-accessible-PDF/Program.cs @@ -2,17 +2,17 @@ using Syncfusion.Presentation; using Syncfusion.PresentationRenderer; -//Load the PowerPoint presentation into a stream. -using FileStream fileStreamInput = new(Path.GetFullPath(@"Data/Template.pptx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite); -//Open the existing PowerPoint presentation with the loaded stream. -using IPresentation pptxDoc = Presentation.Open(fileStreamInput) ; -//Instantiation of the PresentationToPdfConverterSettings. -PresentationToPdfConverterSettings pdfConverterSettings = new PresentationToPdfConverterSettings(); -//Enable a flag to preserve structured document tags in the converted PDF document. -pdfConverterSettings.AutoTag = true; -//Convert the PowerPoint document to a PDF document. -using PdfDocument pdfDocument = PresentationToPdfConverter.Convert(pptxDoc, pdfConverterSettings); -//Create new instance of file stream. -using FileStream fileStreamOutput = new(Path.GetFullPath(@"Output/PPTXToPDF.pdf"), FileMode.Create); -//Save the generated PDF to file stream. -pdfDocument.Save(fileStreamOutput); \ No newline at end of file +//Open the existing PowerPoint presentation. +using (IPresentation pptxDoc = Presentation.Open(@"Data/Template.pptx")) +{ + //Instantiate PresentationToPdfConverterSettings. + PresentationToPdfConverterSettings pdfConverterSettings = new PresentationToPdfConverterSettings(); + //Enable a flag to preserve structured document tags in the converted PDF document. + pdfConverterSettings.AutoTag = true; + //Convert the PowerPoint presentation to a PDF document. + using (PdfDocument pdfDocument = PresentationToPdfConverter.Convert(pptxDoc, pdfConverterSettings)) + { + //Save the PDF document to the file system. + pdfDocument.Save(@"Output/PPTXToPDF.pdf"); + } +} \ No newline at end of file diff --git a/PPTX-to-PDF-conversion/Convert-PowerPoint-presentation-to-PDF/.NET/Convert-PowerPoint-presentation-to-PDF/Program.cs b/PPTX-to-PDF-conversion/Convert-PowerPoint-presentation-to-PDF/.NET/Convert-PowerPoint-presentation-to-PDF/Program.cs index e7c73779..233ac147 100644 --- a/PPTX-to-PDF-conversion/Convert-PowerPoint-presentation-to-PDF/.NET/Convert-PowerPoint-presentation-to-PDF/Program.cs +++ b/PPTX-to-PDF-conversion/Convert-PowerPoint-presentation-to-PDF/.NET/Convert-PowerPoint-presentation-to-PDF/Program.cs @@ -2,20 +2,13 @@ using Syncfusion.Presentation; using Syncfusion.PresentationRenderer; -//Open the PowerPoint file stream. -using (FileStream fileStream = new FileStream(Path.GetFullPath(@"Data/Template.pptx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) +//Open the existing PowerPoint presentation. +using (IPresentation pptxDoc = Presentation.Open(Path.GetFullPath("Data/Template.pptx"))) { - //Load an existing PowerPoint Presentation. - using (IPresentation pptxDoc = Presentation.Open(fileStream)) + //Convert the PowerPoint presentation to PDF document. + using (PdfDocument pdfDocument = PresentationToPdfConverter.Convert(pptxDoc)) { - //Convert PowerPoint into PDF document. - using (PdfDocument pdfDocument = PresentationToPdfConverter.Convert(pptxDoc)) - { - //Save the PDF file to file system. - using (FileStream outputStream = new FileStream(Path.GetFullPath(@"Output/PPTXToPDF.pdf"), FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite)) - { - pdfDocument.Save(outputStream); - } - } + //Save the PDF document to the file system. + pdfDocument.Save(@"Output\PPTXToPDF.pdf"); } -} \ No newline at end of file +} diff --git a/PPTX-to-PDF-conversion/Convert-PowerPoint-presentation-to-PDF/ASP.NET-Core/Convert-PowerPoint-Presentation-to-PDF/Controllers/HomeController.cs b/PPTX-to-PDF-conversion/Convert-PowerPoint-presentation-to-PDF/ASP.NET-Core/Convert-PowerPoint-Presentation-to-PDF/Controllers/HomeController.cs index 00782284..68c671b4 100644 --- a/PPTX-to-PDF-conversion/Convert-PowerPoint-presentation-to-PDF/ASP.NET-Core/Convert-PowerPoint-Presentation-to-PDF/Controllers/HomeController.cs +++ b/PPTX-to-PDF-conversion/Convert-PowerPoint-presentation-to-PDF/ASP.NET-Core/Convert-PowerPoint-Presentation-to-PDF/Controllers/HomeController.cs @@ -26,26 +26,22 @@ public IActionResult Index() public ActionResult ConvertPPTXtoPDF() { - //Open the file as Stream - using (FileStream fileStream = new FileStream(Path.GetFullPath("Data/Input.pptx"), FileMode.Open, FileAccess.Read)) + //Open the existing PowerPoint presentation. + using (IPresentation pptxDoc = Presentation.Open(Path.GetFullPath("Data/Input.pptx"))) { - //Open the existing PowerPoint presentation with loaded stream. - using (IPresentation pptxDoc = Presentation.Open(fileStream)) + //Convert the PowerPoint presentation to PDF document. + using (PdfDocument pdfDocument = PresentationToPdfConverter.Convert(pptxDoc)) { - //Convert the PowerPoint document to PDF document. - using (PdfDocument pdfDocument = PresentationToPdfConverter.Convert(pptxDoc)) - { - //Create the MemoryStream to save the converted PDF. - MemoryStream pdfStream = new MemoryStream(); - //Save the converted PDF document to MemoryStream. - pdfDocument.Save(pdfStream); - pdfStream.Position = 0; - //Download PDF document in the browser. - return File(pdfStream, "application/pdf", "Sample.pdf"); - } + //Create the MemoryStream to save the converted PDF. + MemoryStream pdfStream = new MemoryStream(); + //Save the converted PDF document to MemoryStream. + pdfDocument.Save(pdfStream); + pdfStream.Position = 0; + //Download PDF document in the browser. + return File(pdfStream, "application/pdf", "Sample.pdf"); } } - + } public IActionResult Privacy() { diff --git a/PPTX-to-PDF-conversion/Convert-PowerPoint-presentation-to-PDF/ASP.NET-MVC/Convert-PowerPoint-Presentation-to-PDF/Controllers/HomeController.cs b/PPTX-to-PDF-conversion/Convert-PowerPoint-presentation-to-PDF/ASP.NET-MVC/Convert-PowerPoint-Presentation-to-PDF/Controllers/HomeController.cs index 88b9b20b..0b683965 100644 --- a/PPTX-to-PDF-conversion/Convert-PowerPoint-presentation-to-PDF/ASP.NET-MVC/Convert-PowerPoint-Presentation-to-PDF/Controllers/HomeController.cs +++ b/PPTX-to-PDF-conversion/Convert-PowerPoint-presentation-to-PDF/ASP.NET-MVC/Convert-PowerPoint-Presentation-to-PDF/Controllers/HomeController.cs @@ -27,12 +27,15 @@ public ActionResult ConvertPPTXtoPDF() //Converts the PowerPoint Presentation into PDF document using (PdfDocument pdfDocument = PresentationToPdfConverter.Convert(pptxDoc)) { - //Saves the PDF document to MemoryStream. - MemoryStream stream = new MemoryStream(); - pdfDocument.Save(stream); - stream.Position = 0; - //Download PDF document in the browser. - return File(stream, "application/pdf", "Sample.pdf"); + using (MemoryStream stream = new MemoryStream()) + { + pdfDocument.Save(stream); + //Reset stream position before returning it to the browser. + stream.Position = 0; + //Download the PDF document in the browser. + return File(stream, "application/pdf", "Sample.pdf"); + } + } } } diff --git a/PPTX-to-PDF-conversion/Convert-PowerPoint-presentation-to-PDF/ASP.NET/Convert-PowerPoint-Presentation-to-PDF/MainPage.aspx.cs b/PPTX-to-PDF-conversion/Convert-PowerPoint-presentation-to-PDF/ASP.NET/Convert-PowerPoint-Presentation-to-PDF/MainPage.aspx.cs index 0ce4828c..3db4cbd9 100644 --- a/PPTX-to-PDF-conversion/Convert-PowerPoint-presentation-to-PDF/ASP.NET/Convert-PowerPoint-Presentation-to-PDF/MainPage.aspx.cs +++ b/PPTX-to-PDF-conversion/Convert-PowerPoint-presentation-to-PDF/ASP.NET/Convert-PowerPoint-Presentation-to-PDF/MainPage.aspx.cs @@ -23,22 +23,11 @@ protected void OnButtonClicked(object sender, EventArgs e) //Open the existing PowerPoint presentation. using (IPresentation pptxDoc = Presentation.Open(filePath)) { - //Create the MemoryStream to save the converted PDF. - using (MemoryStream pdfStream = new MemoryStream()) + //Convert the PowerPoint presentation to PDF document. + using (PdfDocument pdfDocument = PresentationToPdfConverter.Convert(pptxDoc)) { - //Convert the PowerPoint document to PDF document. - using (PdfDocument pdfDocument = PresentationToPdfConverter.Convert(pptxDoc)) - { - //Save the converted PDF document to MemoryStream. - pdfDocument.Save(pdfStream); - pdfStream.Position = 0; - } - //Create the output PDF file stream - using (FileStream fileStreamOutput = File.Create(Server.MapPath("~/Sample.pdf"))) - { - //Copy the converted PDF stream into created output PDF stream - pdfStream.CopyTo(fileStreamOutput); - } + //Save the converted PDF document to disk. + pdfDocument.Save(Server.MapPath("~/Sample.pdf")); } } } diff --git a/PPTX-to-PDF-conversion/Convert-PowerPoint-presentation-to-PDF/AWS/AWS_Elastic_Beanstalk/Convert-PowerPoint-Presentation-to-PDF/Controllers/HomeController.cs b/PPTX-to-PDF-conversion/Convert-PowerPoint-presentation-to-PDF/AWS/AWS_Elastic_Beanstalk/Convert-PowerPoint-Presentation-to-PDF/Controllers/HomeController.cs index f243bca3..e75d5ff4 100644 --- a/PPTX-to-PDF-conversion/Convert-PowerPoint-presentation-to-PDF/AWS/AWS_Elastic_Beanstalk/Convert-PowerPoint-Presentation-to-PDF/Controllers/HomeController.cs +++ b/PPTX-to-PDF-conversion/Convert-PowerPoint-presentation-to-PDF/AWS/AWS_Elastic_Beanstalk/Convert-PowerPoint-Presentation-to-PDF/Controllers/HomeController.cs @@ -24,27 +24,25 @@ public IActionResult Index() } public ActionResult ConvertPPTXtoPDF() { - using (FileStream inputStream = new FileStream(Path.GetFullPath("wwwroot/Data/Input.pptx"), FileMode.Open, FileAccess.Read)) + //Open the existing PPTX document. + using (IPresentation pptxDoc = Presentation.Open(Path.GetFullPath("wwwroot/Data/Input.pptx"))) { - //Open the existing PPTX document. - using (IPresentation pptxDoc = Presentation.Open(inputStream)) + //Hooks the font substitution event. + pptxDoc.FontSettings.SubstituteFont += FontSettings_SubstituteFont; + //Converts PPTX document into PDF document. + using (PdfDocument pdfDocument = PresentationToPdfConverter.Convert(pptxDoc)) { - //Hooks the font substitution event. - pptxDoc.FontSettings.SubstituteFont += FontSettings_SubstituteFont; - //Converts PPTX document into PDF document. - using (PdfDocument pdfDocument = PresentationToPdfConverter.Convert(pptxDoc)) - { - //Saves the PDF document to MemoryStream. - MemoryStream stream = new MemoryStream(); - pdfDocument.Save(stream); - //Unhooks the font substitution event after converting to PDF. - pptxDoc.FontSettings.SubstituteFont -= FontSettings_SubstituteFont; - stream.Position = 0; - //Download PDF document in the browser. - return File(stream, "application/pdf", "Sample.pdf"); - } + //Saves the PDF document to MemoryStream. + MemoryStream stream = new MemoryStream(); + pdfDocument.Save(stream); + //Unhooks the font substitution event after converting to PDF. + pptxDoc.FontSettings.SubstituteFont -= FontSettings_SubstituteFont; + stream.Position = 0; + //Download PDF document in the browser. + return File(stream, "application/pdf", "Sample.pdf"); } } + } private static void FontSettings_SubstituteFont(object sender, SubstituteFontEventArgs args) { diff --git a/PPTX-to-PDF-conversion/Convert-PowerPoint-presentation-to-PDF/AWS/AWS_Lambda/Convert-PowerPoint-Presentation-to-PDF/Function.cs b/PPTX-to-PDF-conversion/Convert-PowerPoint-presentation-to-PDF/AWS/AWS_Lambda/Convert-PowerPoint-Presentation-to-PDF/Function.cs index b533594f..6a930ba1 100644 --- a/PPTX-to-PDF-conversion/Convert-PowerPoint-presentation-to-PDF/AWS/AWS_Lambda/Convert-PowerPoint-Presentation-to-PDF/Function.cs +++ b/PPTX-to-PDF-conversion/Convert-PowerPoint-presentation-to-PDF/AWS/AWS_Lambda/Convert-PowerPoint-Presentation-to-PDF/Function.cs @@ -22,27 +22,23 @@ public class Function public string FunctionHandler(string input, ILambdaContext context) { string filePath = Path.GetFullPath(@"Data/Input.pptx"); - //Open the file as Stream - using (FileStream fileStreamInput = new FileStream(filePath, FileMode.Open, FileAccess.Read)) + //Open the existing PowerPoint presentation. + using (IPresentation pptxDoc = Presentation.Open(filePath)) { - //Open the existing PowerPoint presentation with loaded stream. - using (IPresentation pptxDoc = Presentation.Open(fileStreamInput)) + //Hooks the font substitution event. + pptxDoc.FontSettings.SubstituteFont += FontSettings_SubstituteFont; + //Convert the PowerPoint document to PDF document. + using (PdfDocument pdfDocument = PresentationToPdfConverter.Convert(pptxDoc)) { - //Hooks the font substitution event. - pptxDoc.FontSettings.SubstituteFont += FontSettings_SubstituteFont; - //Convert the PowerPoint document to PDF document. - using (PdfDocument pdfDocument = PresentationToPdfConverter.Convert(pptxDoc)) - { - //Create the MemoryStream to save the converted PDF. - MemoryStream pdfStream = new MemoryStream(); - //Save the converted PDF document to MemoryStream. - pdfDocument.Save(pdfStream); - //Unhooks the font substitution event after converting to PDF. - pptxDoc.FontSettings.SubstituteFont -= FontSettings_SubstituteFont; - pdfStream.Position = 0; - return Convert.ToBase64String(pdfStream.ToArray()); - } - } + //Create the MemoryStream to save the converted PDF. + MemoryStream pdfStream = new MemoryStream(); + //Save the converted PDF document to MemoryStream. + pdfDocument.Save(pdfStream); + //Unhooks the font substitution event after converting to PDF. + pptxDoc.FontSettings.SubstituteFont -= FontSettings_SubstituteFont; + pdfStream.Position = 0; + return Convert.ToBase64String(pdfStream.ToArray()); + } } } diff --git a/PPTX-to-PDF-conversion/Convert-PowerPoint-presentation-to-PDF/Blazor/Blazor-Web-App-Server/Convert-PPTX-to-PDF/Data/PowerPointService.cs b/PPTX-to-PDF-conversion/Convert-PowerPoint-presentation-to-PDF/Blazor/Blazor-Web-App-Server/Convert-PPTX-to-PDF/Data/PowerPointService.cs index db18d435..75d9f7fe 100644 --- a/PPTX-to-PDF-conversion/Convert-PowerPoint-presentation-to-PDF/Blazor/Blazor-Web-App-Server/Convert-PPTX-to-PDF/Data/PowerPointService.cs +++ b/PPTX-to-PDF-conversion/Convert-PowerPoint-presentation-to-PDF/Blazor/Blazor-Web-App-Server/Convert-PPTX-to-PDF/Data/PowerPointService.cs @@ -8,26 +8,23 @@ public class PowerPointService { public MemoryStream ConvertPPTXtoPDF() { - //Open the file as Stream - using (FileStream sourceStreamPath = new FileStream(@"wwwroot/Input.pptx", FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) + // Open the existing PowerPoint presentation. + using (IPresentation pptxDoc = Presentation.Open("wwwroot/Input.pptx")) { - //Open the existing PowerPoint presentation with loaded stream. - using (IPresentation pptxDoc = Presentation.Open(sourceStreamPath)) + // Convert the PowerPoint presentation to PDF document. + using (PdfDocument pdfDocument = PresentationToPdfConverter.Convert(pptxDoc)) { - //Convert the PowerPoint document to PDF document. - using (PdfDocument pdfDocument = PresentationToPdfConverter.Convert(pptxDoc)) + // Save the converted PDF document to a MemoryStream. + using (MemoryStream pdfStream = new MemoryStream()) { - //Create the MemoryStream to save the converted PDF. - MemoryStream pdfStream = new MemoryStream(); - //Save the converted PDF document to MemoryStream. pdfDocument.Save(pdfStream); + // Reset stream position before returning it to the browser. pdfStream.Position = 0; - - //Download PDF document in the browser. + // Return the PDF document for download in the browser. return pdfStream; } } - } + } } } } \ No newline at end of file diff --git a/PPTX-to-PDF-conversion/Convert-PowerPoint-presentation-to-PDF/GCP/Google_App_Engine/Convert-PPTX-to-PDF/Controllers/HomeController.cs b/PPTX-to-PDF-conversion/Convert-PowerPoint-presentation-to-PDF/GCP/Google_App_Engine/Convert-PPTX-to-PDF/Controllers/HomeController.cs index 319bfa6b..a605d19f 100644 --- a/PPTX-to-PDF-conversion/Convert-PowerPoint-presentation-to-PDF/GCP/Google_App_Engine/Convert-PPTX-to-PDF/Controllers/HomeController.cs +++ b/PPTX-to-PDF-conversion/Convert-PowerPoint-presentation-to-PDF/GCP/Google_App_Engine/Convert-PPTX-to-PDF/Controllers/HomeController.cs @@ -19,25 +19,23 @@ public HomeController(ILogger logger) public ActionResult ConvertPPTXToPDF() { - MemoryStream stream = new MemoryStream(); try { - using (FileStream inputStream = new FileStream(Path.GetFullPath("Data/Input.pptx"), FileMode.Open, FileAccess.Read)) + //Open the existing PPTX document. + using (IPresentation pptxDoc = Presentation.Open(Path.GetFullPath("Data/Input.pptx"))) { - //Opens the existing PPTX document. - using (IPresentation pptxDoc = Presentation.Open(inputStream)) + //Convert the PPTX document into a PDF document. + using (PdfDocument pdfDocument = PresentationToPdfConverter.Convert(pptxDoc)) { - //Converts PPTX document into PDF document. - using (PdfDocument pdfDocument = PresentationToPdfConverter.Convert(pptxDoc)) - { - //Saves the PDF document to MemoryStream. - pdfDocument.Save(stream); - stream.Position = 0; - } + //Create a MemoryStream to hold the converted PDF. + MemoryStream stream = new MemoryStream(); + //Save the PDF document to the MemoryStream. + pdfDocument.Save(stream); + stream.Position = 0; + //Download PDF document in the browser. + return File(stream, "application/pdf", "PPTXtoPDF.pdf"); } } - //Download PDF document in the browser. - return File(stream, "application/pdf", "PPTXtoPDF.pdf"); } catch (Exception ex) { diff --git a/PPTX-to-PDF-conversion/Convert-PowerPoint-presentation-to-PDF/Linux/Convert-PowerPoint-Presentation-to-PDF/Program.cs b/PPTX-to-PDF-conversion/Convert-PowerPoint-presentation-to-PDF/Linux/Convert-PowerPoint-Presentation-to-PDF/Program.cs index 2b2d59d7..b2ba7ee5 100644 --- a/PPTX-to-PDF-conversion/Convert-PowerPoint-presentation-to-PDF/Linux/Convert-PowerPoint-Presentation-to-PDF/Program.cs +++ b/PPTX-to-PDF-conversion/Convert-PowerPoint-presentation-to-PDF/Linux/Convert-PowerPoint-Presentation-to-PDF/Program.cs @@ -12,26 +12,14 @@ class Program { static void Main(string[] args) { - //Open the file as Stream - using (FileStream fileStreamInput = new FileStream(Path.GetFullPath(@"Data/Input.pptx"), FileMode.Open, FileAccess.Read)) + //Open the existing PowerPoint presentation. + using (IPresentation pptxDoc = Presentation.Open(Path.GetFullPath(@"../../../Data/Input.pptx"))) { - //Open the existing PowerPoint presentation with loaded stream. - using (IPresentation pptxDoc = Presentation.Open(fileStreamInput)) + //Convert the PowerPoint presentation to PDF document. + using (PdfDocument pdfDocument = PresentationToPdfConverter.Convert(pptxDoc)) { - //Convert the PowerPoint document to PDF document. - using (PdfDocument pdfDocument = PresentationToPdfConverter.Convert(pptxDoc)) - { - //Save the converted PDF document to MemoryStream. - MemoryStream pdfStream = new MemoryStream(); - pdfDocument.Save(pdfStream); - pdfStream.Position = 0; - //Create FileStream to save the PDF file. - using (FileStream outputStream = new FileStream("Sample.pdf", FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite)) - { - //Saves the PDF file. - pdfDocument.Save(outputStream); - } - } + //Save the PDF document to the file system. + pdfDocument.Save("Sample.pdf"); } } } diff --git a/PPTX-to-PDF-conversion/Convert-PowerPoint-presentation-to-PDF/Mac/Convert-PowerPoint-Presentation-to-PDF/Program.cs b/PPTX-to-PDF-conversion/Convert-PowerPoint-presentation-to-PDF/Mac/Convert-PowerPoint-Presentation-to-PDF/Program.cs index 69d40540..b2ba7ee5 100644 --- a/PPTX-to-PDF-conversion/Convert-PowerPoint-presentation-to-PDF/Mac/Convert-PowerPoint-Presentation-to-PDF/Program.cs +++ b/PPTX-to-PDF-conversion/Convert-PowerPoint-presentation-to-PDF/Mac/Convert-PowerPoint-Presentation-to-PDF/Program.cs @@ -12,25 +12,14 @@ class Program { static void Main(string[] args) { - //Open the file as Stream - using (FileStream fileStreamInput = new FileStream(Path.GetFullPath(@"../../../Data/Input.pptx"), FileMode.Open, FileAccess.Read)) + //Open the existing PowerPoint presentation. + using (IPresentation pptxDoc = Presentation.Open(Path.GetFullPath(@"../../../Data/Input.pptx"))) { - //Open the existing PowerPoint presentation with loaded stream. - using (IPresentation pptxDoc = Presentation.Open(fileStreamInput)) + //Convert the PowerPoint presentation to PDF document. + using (PdfDocument pdfDocument = PresentationToPdfConverter.Convert(pptxDoc)) { - //Convert the PowerPoint document to PDF document. - using (PdfDocument pdfDocument = PresentationToPdfConverter.Convert(pptxDoc)) - { - //Save the converted PDF document to MemoryStream. - MemoryStream pdfStream = new MemoryStream(); - pdfDocument.Save(pdfStream); - pdfStream.Position = 0; - //Save the stream as file. - using (FileStream fileStreamOutput = File.Create("Sample.pdf")) - { - pdfStream.CopyTo(fileStreamOutput); - } - } + //Save the PDF document to the file system. + pdfDocument.Save("Sample.pdf"); } } } diff --git a/PPTX-to-PDF-conversion/Create-fillable-PDF-from-PPTX/.NET/Create-fillable-PDF-from-PPTX/Program.cs b/PPTX-to-PDF-conversion/Create-fillable-PDF-from-PPTX/.NET/Create-fillable-PDF-from-PPTX/Program.cs index f584760d..bc569d73 100644 --- a/PPTX-to-PDF-conversion/Create-fillable-PDF-from-PPTX/.NET/Create-fillable-PDF-from-PPTX/Program.cs +++ b/PPTX-to-PDF-conversion/Create-fillable-PDF-from-PPTX/.NET/Create-fillable-PDF-from-PPTX/Program.cs @@ -2,24 +2,17 @@ using Syncfusion.Presentation; using Syncfusion.PresentationRenderer; -//Open the PowerPoint file stream. -using (FileStream fileStream = new FileStream(Path.GetFullPath(@"Data/Template.pptx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) +//Open the existing PowerPoint presentation. +using (IPresentation pptxDoc = Presentation.Open(@"Data/Template.pptx")) { - //Load an existing PowerPoint Presentation. - using (IPresentation pptxDoc = Presentation.Open(fileStream)) + //Instantiate PresentationToPdfConverterSettings. + PresentationToPdfConverterSettings settings = new PresentationToPdfConverterSettings(); + //Enable a flag to preserve form fields by converting shapes with names starting with 'FormField_' into editable text form fields in the PDF. + settings.PreserveFormFields = true; + //Convert the PowerPoint presentation to a PDF document. + using (PdfDocument pdfDocument = PresentationToPdfConverter.Convert(pptxDoc)) { - // Create new instance for PresentationToPdfConverterSettings - PresentationToPdfConverterSettings settings = new PresentationToPdfConverterSettings(); - //Enables a flag to preserve form fields by converting shapes with names starting with 'FormField_' into editable text form fields in the PDF. - settings.PreserveFormFields = true; - //Convert PowerPoint into PDF document. - using (PdfDocument pdfDocument = PresentationToPdfConverter.Convert(pptxDoc)) - { - //Save the PDF file to file system. - using (FileStream outputStream = new FileStream(Path.GetFullPath(@"Output/PPTXToPDF.pdf"), FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite)) - { - pdfDocument.Save(outputStream); - } - } + //Save the PDF document to the file system. + pdfDocument.Save(@"Output/PPTXToPDF.pdf"); } } \ No newline at end of file diff --git a/PPTX-to-PDF-conversion/Fallback-fonts-based-on-scripttype/.NET/Fallback-fonts-based-on-scripttype/Program.cs b/PPTX-to-PDF-conversion/Fallback-fonts-based-on-scripttype/.NET/Fallback-fonts-based-on-scripttype/Program.cs index 1258338c..029ed831 100644 --- a/PPTX-to-PDF-conversion/Fallback-fonts-based-on-scripttype/.NET/Fallback-fonts-based-on-scripttype/Program.cs +++ b/PPTX-to-PDF-conversion/Fallback-fonts-based-on-scripttype/.NET/Fallback-fonts-based-on-scripttype/Program.cs @@ -8,35 +8,30 @@ internal class Program { static void Main(string[] args) { - //Load the PowerPoint presentation into stream. - using FileStream fileStreamInput = new FileStream(Path.GetFullPath(@"Data/Template.pptx"), FileMode.Open, FileAccess.Read); - //Open the existing PowerPoint presentation with loaded stream. - using IPresentation pptxDoc = Presentation.Open(fileStreamInput); - //Adds fallback font for "Arabic" script type. - pptxDoc.FontSettings.FallbackFonts.Add(ScriptType.Arabic, "Arial, Times New Roman"); - //Adds fallback font for "Hebrew" script type. - pptxDoc.FontSettings.FallbackFonts.Add(ScriptType.Hebrew, "Arial, Courier New"); - //Adds fallback font for "Hindi" script type. - pptxDoc.FontSettings.FallbackFonts.Add(ScriptType.Hindi, "Mangal, Nirmala UI"); - //Adds fallback font for "Chinese" script type. - pptxDoc.FontSettings.FallbackFonts.Add(ScriptType.Chinese, "DengXian, MingLiU"); - //Adds fallback font for "Japanese" script type. - pptxDoc.FontSettings.FallbackFonts.Add(ScriptType.Japanese, "Yu Mincho, MS Mincho"); - //Adds fallback font for "Thai" script type. - pptxDoc.FontSettings.FallbackFonts.Add(ScriptType.Thai, "Tahoma, Microsoft Sans Serif"); - //Adds fallback font for "Korean" script type. - pptxDoc.FontSettings.FallbackFonts.Add(ScriptType.Korean, "Malgun Gothic, Batang"); - //Create the MemoryStream to save the converted PDF. - using MemoryStream pdfStream = new MemoryStream(); - //Convert the PowerPoint document to PDF document. - using PdfDocument pdfDocument = PresentationToPdfConverter.Convert(pptxDoc); - //Save the converted PDF document to MemoryStream. - pdfDocument.Save(pdfStream); - pdfStream.Position = 0; - //Create the output PDF file stream. - using FileStream fileStreamOutput = File.Create(Path.GetFullPath(@"Output/PPTXToPDF.pdf")); - //Copy the converted PDF stream into created output PDF stream. - pdfStream.CopyTo(fileStreamOutput); + //Open the existing PowerPoint presentation. + using (IPresentation pptxDoc = Presentation.Open(@"Data/Template.pptx")) + { + //Adds fallback font for "Arabic" script type. + pptxDoc.FontSettings.FallbackFonts.Add(ScriptType.Arabic, "Arial, Times New Roman"); + //Adds fallback font for "Hebrew" script type. + pptxDoc.FontSettings.FallbackFonts.Add(ScriptType.Hebrew, "Arial, Courier New"); + //Adds fallback font for "Hindi" script type. + pptxDoc.FontSettings.FallbackFonts.Add(ScriptType.Hindi, "Mangal, Nirmala UI"); + //Adds fallback font for "Chinese" script type. + pptxDoc.FontSettings.FallbackFonts.Add(ScriptType.Chinese, "DengXian, MingLiU"); + //Adds fallback font for "Japanese" script type. + pptxDoc.FontSettings.FallbackFonts.Add(ScriptType.Japanese, "Yu Mincho, MS Mincho"); + //Adds fallback font for "Thai" script type. + pptxDoc.FontSettings.FallbackFonts.Add(ScriptType.Thai, "Tahoma, Microsoft Sans Serif"); + //Adds fallback font for "Korean" script type. + pptxDoc.FontSettings.FallbackFonts.Add(ScriptType.Korean, "Malgun Gothic, Batang"); + //Convert the PowerPoint presentation to a PDF document. + using (PdfDocument pdfDocument = PresentationToPdfConverter.Convert(pptxDoc)) + { + //Save the PDF document to the file system. + pdfDocument.Save(@"Output/PPTXToPDF.pdf"); + } + } } } } diff --git a/PPTX-to-PDF-conversion/Fallback-fonts-for-Unicode-range/.NET/Fallback-fonts-for-Unicode-range/Program.cs b/PPTX-to-PDF-conversion/Fallback-fonts-for-Unicode-range/.NET/Fallback-fonts-for-Unicode-range/Program.cs index df3bfbcf..7ad657fb 100644 --- a/PPTX-to-PDF-conversion/Fallback-fonts-for-Unicode-range/.NET/Fallback-fonts-for-Unicode-range/Program.cs +++ b/PPTX-to-PDF-conversion/Fallback-fonts-for-Unicode-range/.NET/Fallback-fonts-for-Unicode-range/Program.cs @@ -4,31 +4,26 @@ using Syncfusion.Presentation; using Syncfusion.PresentationRenderer; -//Load or open an PowerPoint Presentation. -using FileStream inputStream = new(Path.GetFullPath(@"Data/Template.pptx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite); -//Open an existing PowerPoint presentation. -using IPresentation pptxDoc = Presentation.Open(inputStream); -//Adds fallback font for specific unicode range. -// Arabic. -pptxDoc.FontSettings.FallbackFonts.Add(new FallbackFont(0x0600, 0x06ff, "Arial")); -// Hebrew. -pptxDoc.FontSettings.FallbackFonts.Add(new FallbackFont(0x0590, 0x05ff, "Arial")); -// Hindi. -pptxDoc.FontSettings.FallbackFonts.Add(new FallbackFont(0x0900, 0x097F, "Mangal")); -// Chinese. -pptxDoc.FontSettings.FallbackFonts.Add(new FallbackFont(0x4E00, 0x9FFF, "DengXian")); -// Japanese. -pptxDoc.FontSettings.FallbackFonts.Add(new FallbackFont(0x3040, 0x309F, "MS Mincho")); -// Korean. -pptxDoc.FontSettings.FallbackFonts.Add(new FallbackFont(0xAC00, 0xD7A3, "Malgun Gothic")); -//Create the MemoryStream to save the converted PDF. -using MemoryStream pdfStream = new MemoryStream(); -//Convert the PowerPoint document to PDF document. -using PdfDocument pdfDocument = PresentationToPdfConverter.Convert(pptxDoc); -//Save the converted PDF document to MemoryStream. -pdfDocument.Save(pdfStream); -pdfStream.Position = 0; -//Create the output PDF file stream. -using FileStream fileStreamOutput = File.Create(Path.GetFullPath(@"Output/PPTXToPDF.pdf")); -//Copy the converted PDF stream into created output PDF stream. -pdfStream.CopyTo(fileStreamOutput); \ No newline at end of file +//Open the existing PowerPoint presentation. +using (IPresentation pptxDoc = Presentation.Open(@"Data/Template.pptx")) +{ + //Adds fallback font for specific unicode range. + // Arabic. + pptxDoc.FontSettings.FallbackFonts.Add(new FallbackFont(0x0600, 0x06ff, "Arial")); + // Hebrew. + pptxDoc.FontSettings.FallbackFonts.Add(new FallbackFont(0x0590, 0x05ff, "Arial")); + // Hindi. + pptxDoc.FontSettings.FallbackFonts.Add(new FallbackFont(0x0900, 0x097F, "Mangal")); + // Chinese. + pptxDoc.FontSettings.FallbackFonts.Add(new FallbackFont(0x4E00, 0x9FFF, "DengXian")); + // Japanese. + pptxDoc.FontSettings.FallbackFonts.Add(new FallbackFont(0x3040, 0x309F, "MS Mincho")); + // Korean. + pptxDoc.FontSettings.FallbackFonts.Add(new FallbackFont(0xAC00, 0xD7A3, "Malgun Gothic")); + //Convert the PowerPoint presentation to a PDF document. + using (PdfDocument pdfDocument = PresentationToPdfConverter.Convert(pptxDoc)) + { + //Save the PDF document to the file system. + pdfDocument.Save(@"Output/PPTXToPDF.pdf"); + } +} \ No newline at end of file diff --git a/PPTX-to-PDF-conversion/Fallback-symbols-based-on-scripttype/.NET/Fallback-symbols-based-on-scripttype/Program.cs b/PPTX-to-PDF-conversion/Fallback-symbols-based-on-scripttype/.NET/Fallback-symbols-based-on-scripttype/Program.cs index 32700252..8d31bad3 100644 --- a/PPTX-to-PDF-conversion/Fallback-symbols-based-on-scripttype/.NET/Fallback-symbols-based-on-scripttype/Program.cs +++ b/PPTX-to-PDF-conversion/Fallback-symbols-based-on-scripttype/.NET/Fallback-symbols-based-on-scripttype/Program.cs @@ -9,27 +9,22 @@ internal class Program { static void Main(string[] args) { - //Load the PowerPoint presentation into stream. - using FileStream fileStreamInput = new FileStream(Path.GetFullPath(@"Data/Template.pptx"), FileMode.Open, FileAccess.Read); - //Open the existing PowerPoint presentation with loaded stream. - using IPresentation pptxDoc = Presentation.Open(fileStreamInput); - //Adds fallback font for basic symbols like bullet characters. - pptxDoc.FontSettings.FallbackFonts.Add(ScriptType.Symbols, "Segoe UI Symbol, Arial Unicode MS, Wingdings"); - //Adds fallback font for mathematics symbols. - pptxDoc.FontSettings.FallbackFonts.Add(ScriptType.Mathematics, "Cambria Math, Noto Sans Math, Segoe UI Symbol, Arial Unicode MS"); - //Adds fallback font for emojis. - pptxDoc.FontSettings.FallbackFonts.Add(ScriptType.Emoji, "Segoe UI Emoji, Noto Color Emoji, Arial Unicode MS"); - //Create the MemoryStream to save the converted PDF. - using MemoryStream pdfStream = new MemoryStream(); - //Convert the PowerPoint document to PDF document. - using PdfDocument pdfDocument = PresentationToPdfConverter.Convert(pptxDoc); - //Save the converted PDF document to MemoryStream. - pdfDocument.Save(pdfStream); - pdfStream.Position = 0; - //Create the output PDF file stream. - using FileStream fileStreamOutput = File.Create(Path.GetFullPath(@"../../../Output/PPTXToPDF.pdf")); - //Copy the converted PDF stream into created output PDF stream. - pdfStream.CopyTo(fileStreamOutput); + //Open the existing PowerPoint presentation. + using (IPresentation pptxDoc = Presentation.Open(@"Data/Template.pptx")) + { + //Adds fallback font for basic symbols like bullet characters. + pptxDoc.FontSettings.FallbackFonts.Add(ScriptType.Symbols, "Segoe UI Symbol, Arial Unicode MS, Wingdings"); + //Adds fallback font for mathematics symbols. + pptxDoc.FontSettings.FallbackFonts.Add(ScriptType.Mathematics, "Cambria Math, Noto Sans Math, Segoe UI Symbol, Arial Unicode MS"); + //Adds fallback font for emojis. + pptxDoc.FontSettings.FallbackFonts.Add(ScriptType.Emoji, "Segoe UI Emoji, Noto Color Emoji, Arial Unicode MS"); + //Convert the PowerPoint document to PDF document. + using (PdfDocument pdfDocument = PresentationToPdfConverter.Convert(pptxDoc)) + { + //Save the PDF document to the file system. + pdfDocument.Save(@"../../../Output/PPTXToPDF.pdf"); + } + } } } } diff --git a/PPTX-to-PDF-conversion/Initialize-default-fallback-fonts/.NET/Initialize-default-fallback-fonts/Program.cs b/PPTX-to-PDF-conversion/Initialize-default-fallback-fonts/.NET/Initialize-default-fallback-fonts/Program.cs index d82fc598..9a3eb8f8 100644 --- a/PPTX-to-PDF-conversion/Initialize-default-fallback-fonts/.NET/Initialize-default-fallback-fonts/Program.cs +++ b/PPTX-to-PDF-conversion/Initialize-default-fallback-fonts/.NET/Initialize-default-fallback-fonts/Program.cs @@ -3,20 +3,15 @@ using Syncfusion.Presentation; using Syncfusion.PresentationRenderer; -//Load or open an PowerPoint Presentation. -using FileStream inputStream = new(Path.GetFullPath(@"Data/Template.pptx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite); -//Open an existing PowerPoint presentation. -using IPresentation pptxDoc = Presentation.Open(inputStream); -//Use a sets of default FallbackFont collection to IPresentation. -pptxDoc.FontSettings.FallbackFonts.InitializeDefault(); -//Create the MemoryStream to save the converted PDF. -using MemoryStream pdfStream = new(); -//Convert the PowerPoint document to PDF document. -using PdfDocument pdfDocument = PresentationToPdfConverter.Convert(pptxDoc); -//Save the converted PDF document to MemoryStream. -pdfDocument.Save(pdfStream); -pdfStream.Position = 0; -//Create the output PDF file stream. -using FileStream fileStreamOutput = File.Create(Path.GetFullPath(@"Output/PPTXToPDF.pdf")); -//Copy the converted PDF stream into created output PDF stream. -pdfStream.CopyTo(fileStreamOutput); \ No newline at end of file +//Open the existing PowerPoint presentation. +using (IPresentation pptxDoc = Presentation.Open(@"Data/Template.pptx")) +{ + //Initialize the default FallbackFont collection. + pptxDoc.FontSettings.FallbackFonts.InitializeDefault(); + //Convert the PowerPoint presentation to a PDF document. + using (PdfDocument pdfDocument = PresentationToPdfConverter.Convert(pptxDoc)) + { + //Save the PDF document to the file system. + pdfDocument.Save(@"Output/PPTXToPDF.pdf"); + } +} \ No newline at end of file diff --git a/PPTX-to-PDF-conversion/Modify-the-exiting-fallback-fonts/.NET/Modify-the-exiting-fallback-fonts/Program.cs b/PPTX-to-PDF-conversion/Modify-the-exiting-fallback-fonts/.NET/Modify-the-exiting-fallback-fonts/Program.cs index fb380906..ecbf4685 100644 --- a/PPTX-to-PDF-conversion/Modify-the-exiting-fallback-fonts/.NET/Modify-the-exiting-fallback-fonts/Program.cs +++ b/PPTX-to-PDF-conversion/Modify-the-exiting-fallback-fonts/.NET/Modify-the-exiting-fallback-fonts/Program.cs @@ -4,28 +4,23 @@ using Syncfusion.Presentation; using Syncfusion.PresentationRenderer; -//Load or open an PowerPoint Presentation. -using FileStream inputStream = new(Path.GetFullPath(@"Data/Template.pptx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite); -//Open an existing PowerPoint presentation. -using IPresentation pptxDoc = Presentation.Open(inputStream); -//Use a sets of default FallbackFont collection to IPresentation. -pptxDoc.FontSettings.FallbackFonts.InitializeDefault(); -// Customize a default fallback font name. -FallbackFonts fallbackFonts = pptxDoc.FontSettings.FallbackFonts; -foreach (FallbackFont fallbackFont in fallbackFonts) +//Open the existing PowerPoint presentation. +using (IPresentation pptxDoc = Presentation.Open(@"Data/Template.pptx")) { - //Customize a default fallback font name as "David" for the Hebrew script. - if (fallbackFont.ScriptType == ScriptType.Hebrew) - fallbackFont.FontNames = "David"; -} -//Create the MemoryStream to save the converted PDF. -using MemoryStream pdfStream = new(); -//Convert the PowerPoint document to PDF document. -using PdfDocument pdfDocument = PresentationToPdfConverter.Convert(pptxDoc); -//Save the converted PDF document to MemoryStream. -pdfDocument.Save(pdfStream); -pdfStream.Position = 0; -//Create the output PDF file stream. -using FileStream fileStreamOutput = File.Create(Path.GetFullPath(@"Output/PPTXToPDF.pdf")); -//Copy the converted PDF stream into created output PDF stream. -pdfStream.CopyTo(fileStreamOutput); \ No newline at end of file + //Initialize the default FallbackFont collection. + pptxDoc.FontSettings.FallbackFonts.InitializeDefault(); + //Customize a default fallback font name. + FallbackFonts fallbackFonts = pptxDoc.FontSettings.FallbackFonts; + foreach (FallbackFont fallbackFont in fallbackFonts) + { + //Customize the default fallback font name to "David" for the Hebrew script. + if (fallbackFont.ScriptType == ScriptType.Hebrew) + fallbackFont.FontNames = "David"; + } + //Convert the PowerPoint presentation to a PDF document. + using (PdfDocument pdfDocument = PresentationToPdfConverter.Convert(pptxDoc)) + { + //Save the PDF document to the file system. + pdfDocument.Save(@"Output/PPTXToPDF.pdf"); + } +} \ No newline at end of file diff --git a/PPTX-to-PDF-conversion/Set-PDF-conformance-level/.NET/Set-PDF-conformance-level/Program.cs b/PPTX-to-PDF-conversion/Set-PDF-conformance-level/.NET/Set-PDF-conformance-level/Program.cs index 8563b95b..576840bd 100644 --- a/PPTX-to-PDF-conversion/Set-PDF-conformance-level/.NET/Set-PDF-conformance-level/Program.cs +++ b/PPTX-to-PDF-conversion/Set-PDF-conformance-level/.NET/Set-PDF-conformance-level/Program.cs @@ -2,17 +2,17 @@ using Syncfusion.Presentation; using Syncfusion.PresentationRenderer; -//Create a file stream to read the PowerPoint presentation file. -using FileStream inputStream = new(Path.GetFullPath(@"Data/Template.pptx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite); -//Open an existing PowerPoint presentation. -using IPresentation pptxDoc = Presentation.Open(inputStream); -//Initialize the conversion settings. -PresentationToPdfConverterSettings pdfConverterSettings = new PresentationToPdfConverterSettings(); -//Set the Pdf conformance level to A1B -pdfConverterSettings.PdfConformanceLevel = PdfConformanceLevel.Pdf_A1B; -//Convert the PowerPoint presentation to PDF file. -using PdfDocument pdfDocument = PresentationToPdfConverter.Convert(pptxDoc, pdfConverterSettings); -//Create new instance of file stream. -using FileStream pdfStream = new(Path.GetFullPath(@"Output/PPTXToPDF.pdf"), FileMode.Create); -//Save the generated PDF to file stream. -pdfDocument.Save(pdfStream); \ No newline at end of file +//Open the existing PowerPoint presentation. +using (IPresentation pptxDoc = Presentation.Open(@"Data/Template.pptx")) +{ + //Initialize the conversion settings. + PresentationToPdfConverterSettings pdfConverterSettings = new PresentationToPdfConverterSettings(); + //Set the PDF conformance level to A1B. + pdfConverterSettings.PdfConformanceLevel = PdfConformanceLevel.Pdf_A1B; + //Convert the PowerPoint presentation to a PDF document. + using (PdfDocument pdfDoc = PresentationToPdfConverter.Convert(pptxDoc, pdfConverterSettings)) + { + //Save the PDF document to the file system. + pdfDoc.Save(@"Output/PPTXToPDF.pdf"); + } +} \ No newline at end of file diff --git a/PPTX-to-PDF-conversion/Show-warning-for-unsupported-elements/.NET/Show-warning-for-unsupported-elements/Program.cs b/PPTX-to-PDF-conversion/Show-warning-for-unsupported-elements/.NET/Show-warning-for-unsupported-elements/Program.cs index 7f8e324c..fb04f4e6 100644 --- a/PPTX-to-PDF-conversion/Show-warning-for-unsupported-elements/.NET/Show-warning-for-unsupported-elements/Program.cs +++ b/PPTX-to-PDF-conversion/Show-warning-for-unsupported-elements/.NET/Show-warning-for-unsupported-elements/Program.cs @@ -2,30 +2,28 @@ using Syncfusion.Presentation; using Syncfusion.PresentationRenderer; -//Load or open an PowerPoint Presentation. -using FileStream inputStream = new(Path.GetFullPath(@"Data/Template.pptx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite); -//Open an existing PowerPoint presentation. -using IPresentation pptxDoc = Presentation.Open(inputStream); -//Instantiation of PresentationToPdfConverterSettings. -PresentationToPdfConverterSettings settings = new() +//Open the existing PowerPoint presentation. +using (IPresentation pptxDoc = Presentation.Open(@"Data/Template.pptx")) { - //Get all the warnings into the collection. - Warning = new DocumentWarning() -}; -//Convert the PowerPoint Presentation into PDF document. -using PdfDocument pdfDocument = PresentationToPdfConverter.Convert(pptxDoc, settings); -//If the PowerPoint to Pdf conversion has been stopped, IsCanceled value will be True, otherwise false. -if (!PresentationToPdfConverter.IsCanceled) -{ - //Save the PDF file. - using FileStream outputStream = new(Path.GetFullPath(@"Output/PPTXToPDF.pdf"), FileMode.OpenOrCreate, FileAccess.ReadWrite); - pdfDocument.Save(outputStream); - outputStream.Position = 0; -} -else -{ - Console.WriteLine("PowerPoint to PDF conversion is stopped , please press any key to exit the application"); - Console.ReadKey(); + //Instantiate PresentationToPdfConverterSettings. + PresentationToPdfConverterSettings settings = new PresentationToPdfConverterSettings(); + //Subscribe to the warnings collection. + settings.Warning = new DocumentWarning(); + //Convert the PowerPoint presentation into a PDF document. + using (PdfDocument pdfDocument = PresentationToPdfConverter.Convert(pptxDoc, settings)) + { + //If the PowerPoint to PDF conversion has been stopped, IsCanceled is true; otherwise it is false. + if (!PresentationToPdfConverter.IsCanceled) + { + //Save the PDF file. + pdfDocument.Save(@"Output/PPTXToPDF.pdf"); + } + else + { + Console.WriteLine("PowerPoint to PDF conversion is stopped. Press any key to exit the application."); + Console.ReadKey(); + } + } } /// @@ -35,28 +33,27 @@ public class DocumentWarning : IWarning { /// - /// Get the Boolen value whether to continue conversion or not. + /// Gets the Boolean value indicating whether to continue the conversion. /// /// Collection of warnings - /// + /// True to continue the conversion; otherwise, false. public bool ShowWarnings(List warningInfo) { - //By default to perform the PowerPoint to PDF conversion by setting the isContinueConversion as true. + //By default, continue the PowerPoint to PDF conversion by setting isContinueConversion to true. bool isContinueConversion = true; foreach (WarningInfo warning in warningInfo) { - //Since there are warnings in the PowerPoint presentation the value of isContinueConversion will be set as false. + //Mark the conversion as interrupted when warnings are present; the loop below can override this. isContinueConversion = false; - //Print the description of the Warining + //Print the description of the warning. Console.WriteLine(warning.Description); if (warning.Description.Contains("Metafile") || warning.Description.Contains("Chart")) { - Console.WriteLine("Type [Y] if you want Do you want to continue Presentation to Pdf conversion or Type [N] to cancel the conversion"); - String confrimation = "y"; - //Based on warning.WarningType enumeration, you can do your manipulation. - //Skips the PowerPoint to Pdf conversion by setting isContinueConversion value as false. - //Continue the PowerPoint to PDF conversion by setting the isContinueConversion as true. - if (confrimation.ToLower().Equals("y")) + Console.WriteLine("Type [Y] if you want to continue the Presentation to PDF conversion, or [N] to cancel the conversion."); + String confirmation = Console.ReadLine(); + //Based on the WarningType enumeration, you can perform custom logic here. + //Continue the PowerPoint to PDF conversion when the user enters Y; otherwise, cancel it. + if (confirmation.ToLower().Equals("y")) isContinueConversion = true; else isContinueConversion = false;