Skip to content

Commit

Permalink
Merge pull request #27 from AkashArul26/master
Browse files Browse the repository at this point in the history
ES-848208 Sample to convert multiple Presentation document to PDFs and zip the PDFs
  • Loading branch information
MohanaselvamJothi authored Nov 10, 2023
2 parents d388e24 + 8305504 commit 68bd99a
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.6.33829.357
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mutiple-Presentation-files-to-PDFs-and-zip", "Mutiple-Presentation-files-to-PDFs-and-zip\Mutiple-Presentation-files-to-PDFs-and-zip.csproj", "{330A9C01-C744-4970-85DF-4B97D219FA57}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{330A9C01-C744-4970-85DF-4B97D219FA57}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{330A9C01-C744-4970-85DF-4B97D219FA57}.Debug|Any CPU.Build.0 = Debug|Any CPU
{330A9C01-C744-4970-85DF-4B97D219FA57}.Release|Any CPU.ActiveCfg = Release|Any CPU
{330A9C01-C744-4970-85DF-4B97D219FA57}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {29B1972B-D5B7-4F4E-AB86-E1CCCECE5F94}
EndGlobalSection
EndGlobal
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<RootNamespace>Mutiple_Presentation_files_to_PDFs_and_zip</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Syncfusion.PresentationRenderer.Net.Core" Version="*" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using Syncfusion.Pdf;
using Syncfusion.Presentation;
using Syncfusion.PresentationRenderer;

//Creating new zip archive
Syncfusion.Compression.Zip.ZipArchive zipArchive = new Syncfusion.Compression.Zip.ZipArchive();
//You can use CompressionLevel to reduce the size of the file.
zipArchive.DefaultCompressionLevel = Syncfusion.Compression.CompressionLevel.Best;

//Get the input files from the folder
string folderName = @"../../../InputDocuments";
string[] inputFiles = Directory.GetFiles(folderName);
DirectoryInfo directoryInfo = new DirectoryInfo(folderName);
List<string> files = new List<string>();
FileInfo[] fileInfo = directoryInfo.GetFiles();
foreach (FileInfo fi in fileInfo)
{
string name = Path.GetFileNameWithoutExtension(fi.Name);
files.Add(name);
}

//Converts each Word documents to PDF documents
for (int i = 0; i < inputFiles.Length; i++)
{
//PDF file name
string outputFileName = files[i] + ".pdf";
//Loads the PowerPoint presentation into stream.
using (FileStream fileStreamInput = new FileStream(inputFiles[i], FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
MemoryStream outputStream = ConvertPresentationToPDF(fileStreamInput);
//Add the converted PDF file to zip
zipArchive.AddItem(outputFileName, outputStream, true, Syncfusion.Compression.FileAttributes.Normal);
}
}

//Zip file name and location
FileStream zipStream = new FileStream(@"../../../OutputPDFs.zip", FileMode.OpenOrCreate, FileAccess.ReadWrite);
zipArchive.Save(zipStream, true);
zipArchive.Close();

MemoryStream ConvertPresentationToPDF(FileStream fileStreamInput)
{
//Open the existing PowerPoint presentation with loaded stream.
using (IPresentation pptxDoc = Presentation.Open(fileStreamInput))
{
//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
MemoryStream fileStreamOutput = new MemoryStream();
//Copy the converted PDF stream into created output PDF stream
pdfStream.CopyTo(fileStreamOutput);
return fileStreamOutput;
}
}
}

0 comments on commit 68bd99a

Please sign in to comment.