-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from AkashArul26/master
ES-848208 Sample to convert multiple Presentation document to PDFs and zip the PDFs
- Loading branch information
Showing
6 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
...le-Presentation-files-to-PDFs-and-zip/.NET/Mutiple-Presentation-files-to-PDFs-and-zip.sln
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 added
BIN
+315 KB
...DFs-and-zip/.NET/Mutiple-Presentation-files-to-PDFs-and-zip/InputDocuments/OLEObject.pptx
Binary file not shown.
Binary file added
BIN
+35.1 KB
...o-PDFs-and-zip/.NET/Mutiple-Presentation-files-to-PDFs-and-zip/InputDocuments/Sample.pptx
Binary file not shown.
Binary file added
BIN
+566 KB
...PDFs-and-zip/.NET/Mutiple-Presentation-files-to-PDFs-and-zip/InputDocuments/Template.pptx
Binary file not shown.
15 changes: 15 additions & 0 deletions
15
...iple-Presentation-files-to-PDFs-and-zip/Mutiple-Presentation-files-to-PDFs-and-zip.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
63 changes: 63 additions & 0 deletions
63
...entation-files-to-PDFs-and-zip/.NET/Mutiple-Presentation-files-to-PDFs-and-zip/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |