Advertisement
andruhovski

A1

Oct 12th, 2020
2,032
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.96 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using Aspose.Pdf;
  6.  
  7. namespace Aspose.PDF.PPTX.Converter
  8. {
  9.     class Program
  10.     {
  11.         static void Main()
  12.         {
  13.             var license = new License();
  14.             license.SetLicense(@"C:\Keys\Aspose.Total.lic");
  15.             var pdfDocuments = new DirectoryInfo(@"C:\tmp\Presentations").GetFiles("*.pdf").Select(fi=>fi.Name);
  16.             foreach (var pdfDocument in pdfDocuments)
  17.             {
  18.                 ConvertPDFtoPPTX(pdfDocument, @"C:\tmp\Presentations");
  19.             }            
  20.            
  21.         }
  22.  
  23.         private static void ConvertPDFtoPPTX(string fileName, string outputPath)
  24.         {
  25.             var outputFileName = Path.Join(outputPath, Path.GetFileName(fileName));
  26.             var document = new Aspose.Pdf.Document(fileName);
  27.            
  28.             foreach (var page in document.Pages)
  29.             {                
  30.                 RemoveAnnotations(page, Pdf.Annotations.AnnotationType.Ink);
  31.                 RemoveAnnotations(page, Pdf.Annotations.AnnotationType.Square);
  32.             }
  33.            
  34.             var options = new Aspose.Pdf.PptxSaveOptions
  35.             {
  36.                 SeparateImages = true
  37.             };
  38.  
  39.             document.Save(outputFileName, options);
  40.         }
  41.  
  42.         private static void RemoveAnnotations(Page page, Aspose.Pdf.Annotations.AnnotationType annotationType)
  43.         {
  44.             var annotations = page.Annotations.Where(a => a.AnnotationType == annotationType).ToArray();
  45.             foreach (var annotation in annotations)
  46.             {
  47.                 page.Annotations.Delete(annotation);
  48.             }
  49.         }
  50.  
  51.         private static void ShowProgressOnConsole(UnifiedSaveOptions.ProgressEventHandlerInfo eventInfo)
  52.         {
  53.             switch (eventInfo.EventType)
  54.             {
  55.                 case ProgressEventType.TotalProgress:
  56.                     Console.WriteLine(String.Format("{0}  - Conversion progress : {1}% .", DateTime.Now.TimeOfDay, eventInfo.Value.ToString()));
  57.                     break;
  58.                 case ProgressEventType.ResultPageCreated:
  59.                     Console.WriteLine(String.Format("{0}  - Result page's {1} of {2} layout created.", DateTime.Now.TimeOfDay, eventInfo.Value.ToString(), eventInfo.MaxValue.ToString()));
  60.                     break;
  61.                 case ProgressEventType.ResultPageSaved:
  62.                     Console.WriteLine(String.Format("{0}  - Result page {1} of {2} exported.", DateTime.Now.TimeOfDay, eventInfo.Value.ToString(), eventInfo.MaxValue.ToString()));
  63.                     break;
  64.                 case ProgressEventType.SourcePageAnalysed:
  65.                     Console.WriteLine(String.Format("{0}  - Source page {1} of {2} analyzed.", DateTime.Now.TimeOfDay, eventInfo.Value.ToString(), eventInfo.MaxValue.ToString()));
  66.                     break;
  67.                 default:
  68.                     break;
  69.             }
  70.         }
  71.     }
  72. }
  73.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement