Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Linq;
- using System.Threading.Tasks;
- using Aspose.Pdf;
- namespace Aspose.PDF.PPTX.Converter
- {
- class Program
- {
- static void Main()
- {
- var license = new License();
- license.SetLicense(@"C:\Keys\Aspose.Total.lic");
- var pdfDocuments = new DirectoryInfo(@"C:\tmp\Presentations").GetFiles("*.pdf").Select(fi=>fi.Name);
- foreach (var pdfDocument in pdfDocuments)
- {
- ConvertPDFtoPPTX(pdfDocument, @"C:\tmp\Presentations");
- }
- }
- private static void ConvertPDFtoPPTX(string fileName, string outputPath)
- {
- var outputFileName = Path.Join(outputPath, Path.GetFileName(fileName));
- var document = new Aspose.Pdf.Document(fileName);
- foreach (var page in document.Pages)
- {
- RemoveAnnotations(page, Pdf.Annotations.AnnotationType.Ink);
- RemoveAnnotations(page, Pdf.Annotations.AnnotationType.Square);
- }
- var options = new Aspose.Pdf.PptxSaveOptions
- {
- SeparateImages = true
- };
- document.Save(outputFileName, options);
- }
- private static void RemoveAnnotations(Page page, Aspose.Pdf.Annotations.AnnotationType annotationType)
- {
- var annotations = page.Annotations.Where(a => a.AnnotationType == annotationType).ToArray();
- foreach (var annotation in annotations)
- {
- page.Annotations.Delete(annotation);
- }
- }
- private static void ShowProgressOnConsole(UnifiedSaveOptions.ProgressEventHandlerInfo eventInfo)
- {
- switch (eventInfo.EventType)
- {
- case ProgressEventType.TotalProgress:
- Console.WriteLine(String.Format("{0} - Conversion progress : {1}% .", DateTime.Now.TimeOfDay, eventInfo.Value.ToString()));
- break;
- case ProgressEventType.ResultPageCreated:
- Console.WriteLine(String.Format("{0} - Result page's {1} of {2} layout created.", DateTime.Now.TimeOfDay, eventInfo.Value.ToString(), eventInfo.MaxValue.ToString()));
- break;
- case ProgressEventType.ResultPageSaved:
- Console.WriteLine(String.Format("{0} - Result page {1} of {2} exported.", DateTime.Now.TimeOfDay, eventInfo.Value.ToString(), eventInfo.MaxValue.ToString()));
- break;
- case ProgressEventType.SourcePageAnalysed:
- Console.WriteLine(String.Format("{0} - Source page {1} of {2} analyzed.", DateTime.Now.TimeOfDay, eventInfo.Value.ToString(), eventInfo.MaxValue.ToString()));
- break;
- default:
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement