/// <summary> /// Converts PowerPoint presentan to OneNote while converting the sections in power point to main pages, and slides to sub pages /// It creates two notebooks, one for the Trainer and one for the student /// </summary> /// <param name="pptOpenXml"></param> /// <param name="imgsPath"></param> /// <param name="note"></param> /// <param name="sectionName"></param> protected override void ConvertPowerPointToOneNote(PowerPointOpenXml pptOpenXml, string imgsPath, OneNoteGenerator note, string sectionName) { string trainerNotebookId = String.Empty; string trainerSectionId = String.Empty; if (IncludeTrainerNotebook()) { // Create the student notebook trainerNotebookId = note.CreateNotebook(TrainerNotebook); trainerSectionId = note.CreateSection(sectionName, trainerNotebookId); } string studentNotebookId = String.Empty; string studentSectionId = String.Empty; if (IncludeStudentNotebook()) { // Create the student notebook studentNotebookId = note.CreateNotebook(StudentNotebook); studentSectionId = note.CreateSection(sectionName, studentNotebookId); } if (pptOpenXml.HasSections()) { List<string> sectionNames = pptOpenXml.GetSectionNames(); List<List<int>> slidesInSections = pptOpenXml.GetSlidesInSections(); if (IncludeTrainerNotebook()) ConvertPowerPointWithSectionsToOneNote(pptOpenXml, imgsPath, note, trainerSectionId, sectionNames, slidesInSections, true); if (IncludeStudentNotebook()) ConvertPowerPointWithSectionsToOneNote(pptOpenXml, imgsPath, note, studentSectionId, sectionNames, slidesInSections, false); } else { if (IncludeTrainerNotebook()) ConvertPowerPointWithoutSectionsToOneNote(pptOpenXml, imgsPath, note, trainerSectionId, true); if (IncludeStudentNotebook()) ConvertPowerPointWithoutSectionsToOneNote(pptOpenXml, imgsPath, note, studentSectionId, false); } }
public void ValidateNonExistFile() { const string inputFile = Utility.NonExistentInputFile; var pptOpenXml = new PowerPointOpenXml(inputFile); var N = pptOpenXml.NumberOfSlides(); }
public static void MyClassInitialize(TestContext testContext) { _mPptOpenXml = new PowerPointOpenXml(TestPptPath); }
/// <summary> /// Helper method to include the common code between the trainer and the student create notebook when converting /// Power Point files that doesn't have sections /// </summary> /// <param name="pptOpenXml"></param> /// <param name="imgsPath"></param> /// <param name="note"></param> /// <param name="sectionId"></param> /// <param name="isTrainer"></param> private void ConvertPowerPointWithoutSectionsToOneNote(PowerPointOpenXml pptOpenXml, string imgsPath, OneNoteGenerator note, string sectionId, bool isTrainer) { for (var i = 1; i <= pptOpenXml.NumberOfSlides(); i++) { string pageId; if (isTrainer) { pageId = InsertPowerPointSlideInOneNote(i, pptOpenXml, imgsPath, note, sectionId, true, StudentNotesTitle, true, TrainerNotesTitle); } else { pageId = InsertPowerPointSlideInOneNote(i, pptOpenXml, imgsPath, note, sectionId, true, StudentNotesTitle, false); } if (!pageId.Equals(String.Empty)) { note.SetShowDate(pageId, false); note.SetShowTime(pageId, false); } } string tocPageId = note.CreateTableOfContentPage(sectionId); note.SetShowDate(tocPageId, false); note.SetShowTime(tocPageId, false); }
/// <summary> /// Helper method to include the common code between the trainer and the student create notebook when converting /// Power Point files that have sections /// </summary> /// <param name="pptOpenXml"></param> /// <param name="imgsPath"></param> /// <param name="note"></param> /// <param name="sectionId"></param> /// <param name="sectionNames"></param> /// <param name="slidesInSections"></param> /// <param name="isTrainer"></param> private void ConvertPowerPointWithSectionsToOneNote(PowerPointOpenXml pptOpenXml, string imgsPath, OneNoteGenerator note, string sectionId, List<string> sectionNames, List<List<int>> slidesInSections, bool isTrainer) { var pptSectionsPageIds = new List<string>(); for (int i = 0; i < sectionNames.Count; i++) { string pptSectionPageId = note.CreatePage(sectionNames[i], sectionId); foreach (var slideNumber in slidesInSections[i]) { string pageId; if (isTrainer) { pageId = InsertPowerPointSlideInOneNote(slideNumber, pptOpenXml, imgsPath, note, sectionId, true, StudentNotesTitle, true, TrainerNotesTitle); } else { pageId = InsertPowerPointSlideInOneNote(slideNumber, pptOpenXml, imgsPath, note, sectionId, true, StudentNotesTitle, false); } if (!pageId.Equals(String.Empty)) { note.SetSubPage(sectionId, pageId); note.SetShowDate(pageId, false); note.SetShowTime(pageId, false); } } pptSectionsPageIds.Add(pptSectionPageId); } string tocPageId = note.CreateTableOfContentPage(sectionId); note.SetShowDate(tocPageId, false); note.SetShowTime(tocPageId, false); foreach (var pptSectionPageId in pptSectionsPageIds) { note.SetCollapsePage(pptSectionPageId); note.SetShowDate(pptSectionPageId, false); note.SetShowTime(pptSectionPageId, false); } }
/// <summary> /// Inserts a power point slide into a given section in OneNote as a page /// </summary> /// <param name="slideNumber"></param> /// <param name="pptOpenXml"></param> /// <param name="imgsPath"></param> /// <param name="note"></param> /// <param name="sectionId"></param> /// <param name="showComments"></param> /// <param name="commentsStr"></param> /// <param name="showNotes"></param> /// <param name="notesStr"></param> /// <param name="hiddenSlideNotIncluded"></param> /// <returns>the page ID</returns> protected string InsertPowerPointSlideInOneNote(int slideNumber, PowerPointOpenXml pptOpenXml, string imgsPath, OneNoteGenerator note, string sectionId, bool showComments = true, string commentsStr = "Comments", bool showNotes = true, string notesStr = "Notes", bool hiddenSlideNotIncluded = true) { // skip hidden slides if (hiddenSlideNotIncluded && pptOpenXml.IsHiddenSlide(slideNumber)) { return String.Empty; } // get the image representing the current slide as HTML string imgPath = String.Format("{0}\\Slide{1}.png", imgsPath, slideNumber); Image img; try { img = Image.FromFile(imgPath); } catch (FileNotFoundException e) { Console.WriteLine("Slide {0} was not converted", slideNumber); Console.WriteLine(e.Message); img = null; } // insert the image string pageTitle = pptOpenXml.GetSlideTitle(slideNumber); pageTitle = String.IsNullOrEmpty(pageTitle) ? String.Format("Slide{0}", slideNumber) : pageTitle; string pageId = note.CreatePage(pageTitle, sectionId); if (img != null) { note.AddImageToPage(pageId, img); img.Dispose(); } // Add comments string slideComments = pptOpenXml.GetSlideComments(slideNumber, false); if (showComments && !String.IsNullOrEmpty(slideComments)) { note.AppendPageContent(pageId, commentsStr + ": \n\n" + slideComments, (int)note.GetPageWidth(pageId)); } // Add notes string slideNotes = pptOpenXml.GetSlideNotes(slideNumber); if (showNotes && !String.IsNullOrEmpty(slideNotes)) { note.AppendPageContent(pageId, notesStr + ": \n\n" + slideNotes, (int)note.GetPageWidth(pageId)); } // remove the author note.RemoveAuthor(pageId); return pageId; }
/// <summary> /// Converts PowerPoint presentan to OneNote while converting the sections in power point to main pages, and slides to sub pages /// </summary> /// <param name="pptOpenXml"></param> /// <param name="imgsPath"></param> /// <param name="note"></param> /// <param name="sectionName"></param> protected virtual void ConvertPowerPointToOneNote(PowerPointOpenXml pptOpenXml, string imgsPath, OneNoteGenerator note, string sectionName) { string notebookId = note.CreateNotebook(GetSupportedInputFormat()); string sectionId = note.CreateSection(sectionName, notebookId); if (pptOpenXml.HasSections()) { List<string> sectionNames = pptOpenXml.GetSectionNames(); List<List<int>> slidesInSections = pptOpenXml.GetSlidesInSections(); var pptSectionsPageIds = new List<string>(); for (int i = 0; i < sectionNames.Count; i++) { string pptSectionPageId = note.CreatePage(sectionNames[i], sectionId); foreach (var slideNumber in slidesInSections[i]) { string pageId = InsertPowerPointSlideInOneNote(slideNumber, pptOpenXml, imgsPath, note, sectionId); if (!String.IsNullOrEmpty(pageId)) { note.SetSubPage(sectionId, pageId); } } pptSectionsPageIds.Add(pptSectionPageId); } note.CreateTableOfContentPage(sectionId); foreach (var pptSectionPageId in pptSectionsPageIds) { note.SetCollapsePage(pptSectionPageId); } } else { for (var i = 1; i <= pptOpenXml.NumberOfSlides(); i++) { InsertPowerPointSlideInOneNote(i, pptOpenXml, imgsPath, note, sectionId); } } }
/// <summary> /// Converts PowerPoint presentation into OneNote section /// </summary> /// <param name="inputFile"></param> /// <param name="outputDir"></param> /// <returns></returns> public virtual bool ConvertPowerPointToOneNote(string inputFile, string outputDir) { // Get the name of the file string inputFileName = Path.GetFileNameWithoutExtension(inputFile); // Convert presentation slides to images string imgsPath = ConvertPowerPointToImages(inputFile, outputDir); // Create a new OneNote Notebook var note = new OneNoteGenerator(outputDir); // Convert to OneNote var pptOpenXml = new PowerPointOpenXml(inputFile); ConvertPowerPointToOneNote(pptOpenXml, imgsPath, note, inputFileName); // Delete the temperory imgs directory Utility.DeleteDirectory(imgsPath); return true; }