Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,18 @@ public IActionResult Index()
/// <returns></returns>
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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,11 @@
<PackageReference Include="HarfBuzzSharp.NativeAssets.Linux" Version="8.3.0.1" />
<PackageReference Include="Syncfusion.PresentationRenderer.Net.Core" Version="*" />
</ItemGroup>

<ItemGroup>
<None Update="Data\Input.pptx">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,11 @@
<ItemGroup>
<PackageReference Include="Syncfusion.PresentationRenderer.Net.Core" Version="*" />
</ItemGroup>

<ItemGroup>
<None Update="Data/Input.pptx">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
Loading
Loading