/// <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); } } }
/// <summary> /// Converts PDF file to OneNote by including an image for each page in the document /// </summary> /// <param name="inputFile">PDF document path</param> /// <param name="outputDir">Directory of the output OneNote Notebook</param> /// <returns></returns> public virtual bool ConvertPdfToOneNote(string inputFile, string outputDir) { //Get the name of the file string inputFileName = Path.GetFileNameWithoutExtension(inputFile); //Create a new OneNote Notebook var note = new OneNoteGenerator(outputDir); string notebookId = note.CreateNotebook(GetSupportedInputFormat()); string sectionId = note.CreateSection(inputFileName, notebookId); using (var rasterizer = new GhostscriptRasterizer()) { rasterizer.Open(inputFile); for (var i = 1; i <= rasterizer.PageCount; i++) { Image img = rasterizer.GetPage(160, 160, i); MemoryStream stream = new MemoryStream(); img.Save(stream, ImageFormat.Png); img = Image.FromStream(stream); string pageId = note.CreatePage(String.Format("Page{0}", i), sectionId); note.AddImageToPage(pageId, img); } } note.CreateTableOfContentPage(sectionId); return(true); }
public static void InitializeTestNotebook(TestContext testContext) { _mXmlNs = Utility.NS; _mTestNotebookDir = Path.GetTempPath(); _mOneNoteGenerator = new OneNoteGenerator(_mTestNotebookDir); _mTestNotebookId = _mOneNoteGenerator.CreateNotebook(TestNotebookName); _mTestSectionId = _mOneNoteGenerator.CreateSection(TestSectionName, _mTestNotebookId); //for ValidateCreateSectionNameConflicts() _mOneNoteGenerator.CreateSection(TestSectionName, _mTestNotebookId); _mOneNoteGenerator.CreateSection(TestSectionName, _mTestNotebookId); _mTestPageId = _mOneNoteGenerator.CreatePage(TestPageName, _mTestSectionId); //This is ugly, but apparently creating notebook/section/page takes time Thread.Sleep(4000); }
/// <summary> /// Converts the Word document input file into OneNote /// </summary> /// <param name="inputFile"></param> /// <param name="outputDir"></param> public virtual bool ConvertWordToOneNote(string inputFile, string outputDir) { var retVal = false; string inputFileName = Path.GetFileNameWithoutExtension(inputFile); var tempPath = outputDir + "\\temp\\"; if (!Directory.Exists(tempPath)) { Directory.CreateDirectory(tempPath); } object tempHtmlFilePath = tempPath + inputFileName + HtmlFileExtension; object htmlFilteredFormat = WdSaveFormat.wdFormatFilteredHTML; //used to get pictures in word document object auxiliaryFilePath = tempPath + inputFileName + AuxFileSuffix; object htmlFormat = WdSaveFormat.wdFormatHTML; var auxiliaryFilePicFolder = auxiliaryFilePath + AuxFileLocationSuffix; var originalFilePicFolder = tempPath + inputFileName + AuxFileLocationSuffix; try { //Save the word document as a HTML file temporarily var word = new WordApplication(); var doc = word.Documents.Open(inputFile); doc.SaveAs(ref tempHtmlFilePath, ref htmlFilteredFormat); doc.SaveAs(ref auxiliaryFilePath, ref htmlFormat); ((_WordDocument)doc).Close(); ((_WordApplication)word).Quit(); //Create a new OneNote Notebook var note = new OneNoteGenerator(outputDir); var notebookId = note.CreateNotebook(GetSupportedInputFormat()); var sectionId = note.CreateSection(inputFileName, notebookId); //Now migrate the content in the temporary HTML file into the newly created OneNote Notebook if (ConvertHtmlToOneNote(tempHtmlFilePath.ToString(), originalFilePicFolder, auxiliaryFilePicFolder, note, sectionId)) { //Generate table of content note.CreateTableOfContentPage(sectionId); retVal = true; } } finally { Utility.DeleteDirectory(tempPath); } return(retVal); }
/// <summary> /// Converts the ePub document input file into OneNote /// </summary> /// <param name="inputFile"></param> /// <param name="outputDir"></param> /// <returns></returns> public virtual bool ConvertEpubToOneNote(string inputFile, string outputDir) { try { // Initialize epub reader class var epub = new EpubReader(inputFile, outputDir); // Get the page contents List <string> pageTitles = epub.GetPageTitles(); List <HtmlDocument> pagesHtml = epub.GetPagesAsHtmlDocuments(); List <string> pagePaths = epub.GetPagePaths(); Dictionary <string, int> pagesLevel = epub.GetPagesLevel(); // Create a new OneNote Notebook var note = new OneNoteGenerator(outputDir); string notebookId = note.CreateNotebook(GetSupportedInputFormat()); string sectionId = note.CreateSection(epub.GetTitle(), notebookId); // Create pages var pageIds = pageTitles.Select(pageTitle => note.CreatePage(pageTitle, sectionId)).ToArray(); // Get links to pages var pageLinks = pageIds.Select(pageId => note.GetHyperLinkToObject(pageId)).ToList(); // Replace links to .html with .one ReplaceEpubLinksFromHtmlToOneNote(pagesHtml, pagePaths, pageLinks); // Add content to pages for (var i = 0; i < pageIds.Length; i++) { note.AppendPageContentAsHtmlBlock(pageIds[i], pagesHtml[i].DocumentNode.OuterHtml); if (pagesLevel.ContainsKey(pagePaths[i])) { note.SetPageLevel(pageIds[i], pagesLevel[pagePaths[i]]); } } return(true); } catch (Exception e) { Console.WriteLine(@"Error in ConvertEpubToOneNote for file {0}: {1}", inputFile, e.Message); return(false); } }
/// <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 the InDesign document input file into OneNote /// </summary> /// <param name="inputFile"></param> /// <param name="outputDir"></param> /// <returns></returns> public virtual bool ConvertInDesignToOneNote(string inputFile, string outputDir) { #if INDESIGN_INSTALLED // get the file name string inputFileName = Path.GetFileNameWithoutExtension(inputFile); // gets the InDesign App Type inDesignAppType = Type.GetTypeFromProgID(ConfigurationManager.AppSettings.Get("InDesignProgId")); if (inDesignAppType == null) { throw new InvalidOperationException("Failed to find InDesign application. Please ensure that it is installed and is running on your machine."); } InDesignApplication app = (InDesignApplication)Activator.CreateInstance(inDesignAppType, true); // open the indd file try { app.Open(inputFile); } catch (Exception e) { Console.WriteLine(@"Error in ConvertInDesignToOneNote for file {0}: {1}", inputFile, e.Message); return(false); } InDesignDocument doc = app.ActiveDocument; // temp directory for html string htmlDir = Utility.CreateDirectory(Utility.NewFolderPath(outputDir, "html")); // Get the file name string htmlFile = Utility.NewFilePath(htmlDir, inputFileName, HtmlFileExtension); // Save the html file SetInDesignHtmlExportOptions(doc); doc.Export(idExportFormat.idHTML, htmlFile); // Create a new OneNote Notebook var note = new OneNoteGenerator(outputDir); string notebookId = note.CreateNotebook(GetSupportedInputFormat()); string sectionId = note.CreateSection(inputFileName, notebookId); // get the html var htmlDoc = new HtmlDocument(); htmlDoc.Load(htmlFile); // change the links to have the full path ModifyInDesignHtmlLinks(htmlDoc, htmlDir); // get the title string title = GetInDesignTitle(htmlDoc); string pageId = note.CreatePage(title, sectionId); note.AddPageContentAsHtmlBlock(pageId, htmlDoc.DocumentNode.OuterHtml); return(true); #else throw new NotImplementedException(); #endif }