Skip to content

Commit 847507d

Browse files
added changes for presentation conversion
1 parent 58e83ae commit 847507d

36 files changed

Lines changed: 519 additions & 602 deletions

File tree

  • PPTX-to-Image-conversion
  • PPTX-to-PDF-conversion
    • Apply-substitution-font-name/.NET/Apply-substitution-font-name
    • Apply-substitution-font-stream/.NET/Apply-substitution-font-stream
    • Convert-PowerPoint-into-accessible-PDF/.NET/Convert-PowerPoint-into-accessible-PDF
    • Convert-PowerPoint-presentation-to-PDF
    • Create-fillable-PDF-from-PPTX/.NET/Create-fillable-PDF-from-PPTX
    • Fallback-fonts-based-on-scripttype/.NET/Fallback-fonts-based-on-scripttype
    • Fallback-fonts-for-Unicode-range/.NET/Fallback-fonts-for-Unicode-range
    • Fallback-symbols-based-on-scripttype/.NET/Fallback-symbols-based-on-scripttype
    • Initialize-default-fallback-fonts/.NET/Initialize-default-fallback-fonts
    • Modify-the-exiting-fallback-fonts/.NET/Modify-the-exiting-fallback-fonts
    • Set-PDF-conformance-level/.NET/Set-PDF-conformance-level
    • Show-warning-for-unsupported-elements/.NET/Show-warning-for-unsupported-elements

PPTX-to-Image-conversion/Convert-PowerPoint-presentation-to-Image/.NET/Convert-PowerPoint-presentation-to-Image/Program.cs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,22 @@ internal class Program
88
{
99
static void Main(string[] args)
1010
{
11-
//Open the file as Stream.
12-
using (FileStream fileStream = new FileStream(Path.GetFullPath(@"Data/Template.pptx"), FileMode.Open, FileAccess.Read))
11+
//Open the existing PowerPoint presentation.
12+
using (IPresentation pptxDoc = Presentation.Open(@"Data/Template.pptx"))
1313
{
14-
//Open the existing PowerPoint presentation.
15-
using (IPresentation pptxDoc = Presentation.Open(fileStream))
14+
//Initialize the PresentationRenderer to perform image conversion.
15+
pptxDoc.PresentationRenderer = new PresentationRenderer();
16+
//Convert PowerPoint slide to image as stream.
17+
Stream[] images = pptxDoc.RenderAsImages(ExportImageFormat.Jpeg);
18+
//Save the images to file.
19+
for (int i = 0; i < images.Length; i++)
1620
{
17-
//Initialize PresentationRenderer.
18-
pptxDoc.PresentationRenderer = new PresentationRenderer();
19-
//Convert PowerPoint to image as stream.
20-
Stream[] images = pptxDoc.RenderAsImages(ExportImageFormat.Jpeg);
21-
//Save the images to file.
22-
for (int i = 0; i < images.Length; i++)
21+
using (Stream stream = images[i])
2322
{
24-
using (Stream stream = images[i])
23+
//Save the image stream to a file.
24+
using (FileStream fileStreamOutput = File.Create(Path.GetFullPath("Output/Image" + i + ".jpg")))
2525
{
26-
//Save the image stream to a file.
27-
using (FileStream fileStreamOutput = File.Create(Path.GetFullPath("Output/Image" + i + ".jpg")))
28-
{
29-
stream.CopyTo(fileStreamOutput);
30-
}
26+
stream.CopyTo(fileStreamOutput);
3127
}
3228
}
3329
}

PPTX-to-Image-conversion/Convert-PowerPoint-presentation-to-Image/ASP.NET-Core/Convert-PowerPoint-Presentation-to-Image/Controllers/HomeController.cs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,18 @@ public IActionResult Index()
2828
/// <returns></returns>
2929
public ActionResult ConvertPPTXtoImage(string button)
3030
{
31-
//Open the file as Stream.
32-
using (FileStream fileStream = new FileStream(Path.GetFullPath("Data/Input.pptx"), FileMode.Open, FileAccess.Read))
31+
//Open an existing PowerPoint presentation.
32+
using (IPresentation pptxDoc = Presentation.Open("Data/Input.pptx"))
3333
{
34-
//Open the existing PowerPoint presentation.
35-
using (IPresentation pptxDoc = Presentation.Open(fileStream))
36-
{
37-
//Initialize the PresentationRenderer to perform image conversion.
38-
pptxDoc.PresentationRenderer = new PresentationRenderer();
39-
//Convert PowerPoint slide to image as stream.
40-
Stream stream = pptxDoc.Slides[0].ConvertToImage(ExportImageFormat.Jpeg);
41-
//Reset the stream position.
42-
stream.Position = 0;
43-
//Download image in the browser.
44-
return File(stream, "application/jpeg", "PPTXtoImage.Jpeg");
45-
}
46-
}
34+
//Initialize the PresentationRenderer to perform image conversion.
35+
pptxDoc.PresentationRenderer = new PresentationRenderer();
36+
//Convert PowerPoint slide to image as stream.
37+
Stream stream = pptxDoc.Slides[0].ConvertToImage(ExportImageFormat.Jpeg);
38+
//Reset the stream position.
39+
stream.Position = 0;
40+
//Download image in the browser.
41+
return File(stream, "application/jpeg", "PPTXtoImage.Jpeg");
42+
}
4743
}
4844

4945
public IActionResult Privacy()

PPTX-to-Image-conversion/Convert-PowerPoint-presentation-to-Image/ASP.NET-MVC/Convert-PowerPoint-Presentation-to-Image/Controllers/HomeController.cs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,13 @@ public ActionResult Index()
1818
}
1919
public void ConvertPPTXtoImage()
2020
{
21-
//Open the file as Stream.
22-
using (FileStream pathStream = new FileStream(Server.MapPath("~/App_Data/Input.pptx"), FileMode.Open, FileAccess.Read))
21+
// Opens a PowerPoint Presentation.
22+
using (IPresentation pptxDoc = Presentation.Open(Server.MapPath("~/App_Data/Input.pptx")))
2323
{
24-
//Opens a PowerPoint Presentation.
25-
using (IPresentation pptxDoc = Presentation.Open(pathStream))
26-
{
27-
//Convert the first slide into image.
28-
Image image = pptxDoc.Slides[0].ConvertToImage(Syncfusion.Drawing.ImageType.Metafile);
29-
//Saves the image file to MemoryStream.
30-
MemoryStream stream = new MemoryStream();
31-
//Download image file in the browser.
32-
ExportAsImage(image, "PPTXToImage.Jpeg", ImageFormat.Jpeg, HttpContext.ApplicationInstance.Response);
33-
}
24+
//Convert the first slide into image.
25+
Image image = pptxDoc.Slides[0].ConvertToImage(Syncfusion.Drawing.ImageType.Metafile);
26+
//Download image file in the browser.
27+
ExportAsImage(image, "PPTXToImage.Jpeg", ImageFormat.Jpeg, HttpContext.ApplicationInstance.Response);
3428
}
3529
}
3630
//To download the image file.

PPTX-to-Image-conversion/Convert-PowerPoint-presentation-to-Image/Blazor/Web-Server-App/Convert-PPTX-to-Image/Data/PowerPointService.cs

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,22 @@ public class PowerPointService
99
{
1010
public MemoryStream ConvertPPTXtoImage()
1111
{
12-
//Open the file as Stream.
13-
using (FileStream sourceStreamPath = new FileStream(@"wwwroot/Input.pptx", FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
12+
//Opens an existing PowerPoint presentation from the wwwroot folder.
13+
using (IPresentation pptxDoc = Presentation.Open(Path.Combine("wwwroot", "Input.pptx")))
1414
{
15-
//Open the existing PowerPoint presentation with loaded stream.
16-
using (IPresentation pptxDoc = Presentation.Open(sourceStreamPath))
15+
//Initialize the PresentationRenderer to perform image conversion.
16+
pptxDoc.PresentationRenderer = new PresentationRenderer();
17+
//Convert PowerPoint slide to image as stream.
18+
using (Stream stream = pptxDoc.Slides[0].ConvertToImage(ExportImageFormat.Jpeg))
1719
{
18-
//Initialize the PresentationRenderer to perform image conversion.
19-
pptxDoc.PresentationRenderer = new PresentationRenderer();
20-
//Convert PowerPoint slide to image as stream.
21-
using (Stream stream = pptxDoc.Slides[0].ConvertToImage(ExportImageFormat.Jpeg))
22-
{
23-
//Save the converted image file to MemoryStream.
24-
MemoryStream Stream = new MemoryStream();
25-
stream.CopyTo(Stream);
26-
Stream.Position = 0;
27-
//Download image file in the browser.
28-
return Stream;
29-
}
20+
//Save the converted image file to MemoryStream.
21+
MemoryStream outputStream = new MemoryStream();
22+
stream.CopyTo(outputStream);
23+
outputStream.Position = 0;
24+
//Return the image stream for download in the browser.
25+
return outputStream;
3026
}
31-
}
27+
}
3228
}
3329
}
3430
}

PPTX-to-Image-conversion/Convert-PowerPoint-presentation-to-Image/GCP/Google_App_Engine/Convert-PPTX-to-image/Controllers/HomeController.cs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,17 @@ public ActionResult ConvertPPTXToImage()
2020
MemoryStream stream = new MemoryStream();
2121
try
2222
{
23-
using (FileStream inputStream = new FileStream(Path.GetFullPath("Data/Input.pptx"), FileMode.Open, FileAccess.Read))
23+
//Open the existing PPTX document.
24+
using (IPresentation pptxDoc = Presentation.Open(Path.GetFullPath("Data/Input.pptx")))
2425
{
25-
//Opens the existing PPTX document.
26-
using (IPresentation pptxDoc = Presentation.Open(inputStream))
27-
{
28-
//Initialize the PresentationRenderer to perform image conversion.
29-
pptxDoc.PresentationRenderer = new PresentationRenderer();
30-
//Convert PowerPoint slide to image as stream.
31-
stream = (MemoryStream)pptxDoc.Slides[0].ConvertToImage(ExportImageFormat.Jpeg);
32-
}
26+
//Initialize the PresentationRenderer to perform image conversion.
27+
pptxDoc.PresentationRenderer = new PresentationRenderer();
28+
//Convert PowerPoint slide to image as stream.
29+
stream = (MemoryStream)pptxDoc.Slides[0].ConvertToImage(ExportImageFormat.Jpeg);
30+
stream.Position = 0;
31+
//Download image file in the browser.
32+
return File(stream, "image/jpeg", "PPTXToimage_Page1.jpeg");
3333
}
34-
//Download image in the browser.
35-
return File(stream, "image/jpeg", "PPTXToimage_Page1.jpeg");
3634
}
3735
catch (Exception ex)
3836
{

PPTX-to-Image-conversion/Convert-PowerPoint-presentation-to-Image/Linux/Convert-PowerPoint-Presentation-to-Image/Convert-PowerPoint-Presentation-to-Image.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,11 @@
1313
<PackageReference Include="HarfBuzzSharp.NativeAssets.Linux" Version="8.3.0.1" />
1414
<PackageReference Include="Syncfusion.PresentationRenderer.Net.Core" Version="*" />
1515
</ItemGroup>
16+
17+
<ItemGroup>
18+
<None Update="Data\Input.pptx">
19+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
20+
</None>
21+
</ItemGroup>
22+
1623
</Project>

PPTX-to-Image-conversion/Convert-PowerPoint-presentation-to-Image/Linux/Convert-PowerPoint-Presentation-to-Image/Program.cs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,21 @@ class Program
1111
{
1212
static void Main(string[] args)
1313
{
14-
//Open the file as Stream.
15-
using (FileStream fileStreamInput = new FileStream(Path.GetFullPath(@"Data/Input.pptx"), FileMode.Open, FileAccess.Read))
14+
//Open the existing PowerPoint presentation.
15+
using (IPresentation pptxDoc = Presentation.Open("Data/Input.pptx"))
1616
{
17-
//Open the existing PowerPoint presentation with loaded stream.
18-
using (IPresentation pptxDoc = Presentation.Open(fileStreamInput))
17+
//Initialize the PresentationRenderer to perform image conversion.
18+
pptxDoc.PresentationRenderer = new PresentationRenderer();
19+
//Convert PowerPoint slide to image as stream.
20+
using (Stream stream = pptxDoc.Slides[0].ConvertToImage(ExportImageFormat.Jpeg))
1921
{
20-
//Initialize the PresentationRenderer to perform image conversion.
21-
pptxDoc.PresentationRenderer = new PresentationRenderer();
22-
//Convert PowerPoint slide to image as stream.
23-
using (Stream stream = pptxDoc.Slides[0].ConvertToImage(ExportImageFormat.Jpeg))
22+
//Reset the stream position.
23+
stream.Position = 0;
24+
//Create FileStream to save the image file.
25+
using (FileStream outputStream = new FileStream("PPTXtoImage.Jpeg", FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite))
2426
{
25-
//Reset the stream position.
26-
stream.Position = 0;
27-
//Create FileStream to save the image file.
28-
using (FileStream outputStream = new FileStream("PPTXtoImage.Jpeg", FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite))
29-
{
30-
//Save the image file.
31-
stream.CopyTo(outputStream);
32-
}
27+
//Save the image file.
28+
stream.CopyTo(outputStream);
3329
}
3430
}
3531
}

PPTX-to-Image-conversion/Convert-PowerPoint-presentation-to-Image/MAC/Convert-PowerPoint-Presentation-to-Image/Convert-PowerPoint-Presentation-to-Image.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,11 @@
1111
<ItemGroup>
1212
<PackageReference Include="Syncfusion.PresentationRenderer.Net.Core" Version="*" />
1313
</ItemGroup>
14+
15+
<ItemGroup>
16+
<None Update="Data/Input.pptx">
17+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
18+
</None>
19+
</ItemGroup>
20+
1421
</Project>

PPTX-to-Image-conversion/Convert-PowerPoint-presentation-to-Image/MAC/Convert-PowerPoint-Presentation-to-Image/Program.cs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,21 @@ class Program
1111
{
1212
static void Main(string[] args)
1313
{
14-
//Open the file as Stream.
15-
using (FileStream fileStreamInput = new FileStream(Path.GetFullPath(@"../../../Data/Input.pptx"), FileMode.Open, FileAccess.Read))
14+
//Open the existing PowerPoint presentation.
15+
using (IPresentation pptxDoc = Presentation.Open("Data/Input.pptx"))
1616
{
17-
//Open the existing PowerPoint presentation with loaded stream.
18-
using (IPresentation pptxDoc = Presentation.Open(fileStreamInput))
17+
//Initialize the PresentationRenderer to perform image conversion.
18+
pptxDoc.PresentationRenderer = new PresentationRenderer();
19+
//Convert PowerPoint slide to image as stream.
20+
using (Stream stream = pptxDoc.Slides[0].ConvertToImage(ExportImageFormat.Jpeg))
1921
{
20-
//Initialize the PresentationRenderer to perform image conversion.
21-
pptxDoc.PresentationRenderer = new PresentationRenderer();
22-
//Convert PowerPoint slide to image as stream.
23-
using (Stream stream = pptxDoc.Slides[0].ConvertToImage(ExportImageFormat.Jpeg))
22+
//Reset the stream position.
23+
stream.Position = 0;
24+
//Create FileStream to save the image file.
25+
using (FileStream outputStream = new FileStream("PPTXtoImage.Jpeg", FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite))
2426
{
25-
//Reset the stream position.
26-
stream.Position = 0;
27-
//Create FileStream to save the image file.
28-
using (FileStream outputStream = new FileStream("PPTXtoImage.Jpeg", FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite))
29-
{
30-
//Save the image file.
31-
stream.CopyTo(outputStream);
32-
}
27+
//Save the image file.
28+
stream.CopyTo(outputStream);
3329
}
3430
}
3531
}
Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
11
using Syncfusion.Presentation;
22
using Syncfusion.PresentationRenderer;
33

4-
//Open an existing presentation.
5-
using (FileStream inputStream = new(Path.GetFullPath(@"Data/Template.pptx"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
4+
//Open the existing PowerPoint presentation.
5+
using (IPresentation pptxDoc = Presentation.Open(@"Data/Template.pptx"))
66
{
7-
//Load the presentation.
8-
using (IPresentation pptxDoc = Presentation.Open(inputStream))
7+
//Initialize PresentationRenderer.
8+
pptxDoc.PresentationRenderer = new PresentationRenderer();
9+
//Convert the PowerPoint slide as an image stream.
10+
using (Stream stream = pptxDoc.Slides[0].ConvertToImage(ExportImageFormat.Jpeg))
911
{
10-
//Initialize PresentationRenderer.
11-
pptxDoc.PresentationRenderer = new PresentationRenderer();
12-
//Convert the PowerPoint slide as an image stream.
13-
using (Stream stream = pptxDoc.Slides[0].ConvertToImage(ExportImageFormat.Jpeg))
12+
//Save the image stream to a file.
13+
using (FileStream fileStreamOutput = File.Create(@"Output/Image.jpg"))
1414
{
15-
//Save the image stream to a file.
16-
using (FileStream fileStreamOutput = File.Create(Path.GetFullPath(@"Output/Image.jpg")))
17-
{
18-
stream.CopyTo(fileStreamOutput);
19-
}
20-
}
21-
}
15+
stream.CopyTo(fileStreamOutput);
16+
}
17+
}
2218
}

0 commit comments

Comments
 (0)