Program.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. using System;
  2. using System.IO;
  3. using ClearSlideLibrary.HtmlController;
  4. using ClearSlideLibrary.PPTBuilder;
  5. using ClearSlideLibrary.Dom;
  6. using System.Windows.Forms;
  7. using System.ComponentModel;
  8. using System.Drawing;
  9. namespace ClearSlideConsole
  10. {
  11. public class Program : System.Windows.Forms.Form
  12. {
  13. private TextBox textBox1;
  14. private Button button1;
  15. private OpenFileDialog openFileDialog1;
  16. public Program()
  17. {
  18. InitializeComponent();
  19. }
  20. [STAThread]
  21. static void Main()
  22. {
  23. Application.EnableVisualStyles();
  24. Application.Run(new Program());
  25. }
  26. private void InitializeComponent()
  27. {
  28. this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
  29. this.textBox1 = new System.Windows.Forms.TextBox();
  30. this.button1 = new System.Windows.Forms.Button();
  31. this.SuspendLayout();
  32. this.openFileDialog1.FileName = "openFileDialog1";
  33. this.textBox1.Location = new System.Drawing.Point(24, 44);
  34. this.textBox1.Name = "textBox1";
  35. this.textBox1.Size = new System.Drawing.Size(247, 20);
  36. this.textBox1.TabIndex = 0;
  37. this.button1.Location = new System.Drawing.Point(286, 41);
  38. this.button1.Name = "button1";
  39. this.button1.Size = new System.Drawing.Size(75, 23);
  40. this.button1.TabIndex = 1;
  41. this.button1.Text = "choose file";
  42. this.button1.UseVisualStyleBackColor = true;
  43. this.button1.Click += new System.EventHandler(this.ChooseFile);
  44. this.ClientSize = new System.Drawing.Size(379, 127);
  45. this.Controls.Add(this.button1);
  46. this.Controls.Add(this.textBox1);
  47. this.Name = "ClearSlide";
  48. this.Text = "ClearSlide";
  49. this.ResumeLayout(false);
  50. this.PerformLayout();
  51. }
  52. private void ChooseFile(object sender, EventArgs e)
  53. {
  54. // Create an instance of the open file dialog box.
  55. OpenFileDialog openFileDialog1 = new OpenFileDialog();
  56. // Set filter options and filter index.
  57. openFileDialog1.Filter = " (.pptx)|*.pptx|All Files (*.*)|*.*";
  58. openFileDialog1.FilterIndex = 1;
  59. openFileDialog1.Multiselect = true;
  60. // Process input if the user clicked OK.
  61. if (openFileDialog1.ShowDialog() == DialogResult.OK)
  62. {
  63. //Open the selected file to read.
  64. textBox1.Text = openFileDialog1.FileName;
  65. ProcessPresentation();
  66. Application.Exit();
  67. }
  68. }
  69. private void ProcessPresentation()
  70. {
  71. var inf = new FileInfo(textBox1.Text);
  72. string file = Path.GetFileName(textBox1.Text);
  73. string htmlFileName = Path.GetFileNameWithoutExtension(inf.Name);
  74. string dir = Path.GetDirectoryName(Path.GetDirectoryName(Environment.CurrentDirectory));
  75. string destinationDirForHtmlFile = Path.Combine(dir, "PictureExtracts");
  76. string path = textBox1.Text; //Path.Combine(dir, Path.GetFileName(file));
  77. //Generate slide html output file.
  78. var presentationBuilder = new PPTPresenationBuilder();
  79. var pptSlides = presentationBuilder.GetPPTSlides(path);
  80. int width = presentationBuilder.getSlideWidth();
  81. int height = presentationBuilder.getSlideHeight();
  82. int slideCounter = 1;
  83. foreach (PPTSlide pptSlide in pptSlides)
  84. {
  85. var htmlcontroller = new HtmlController(destinationDirForHtmlFile,
  86. htmlFileName, pptSlide,
  87. slideCounter, pptSlides.Count)
  88. {
  89. SlideWidth = width,
  90. SlideHeight = height
  91. };
  92. htmlcontroller.GenerateHtml();
  93. slideCounter++;
  94. }
  95. textBox1.Text = "DONE";
  96. Console.WriteLine(textBox1.Text);
  97. }
  98. }
  99. }