CreateTableOfContentPage() public method

Generates a Table of Content Page of all the pages underneath the given section Also sets the Table of Content Page to be the first page in the given section
public CreateTableOfContentPage ( string sectionId, string tocPageTitle = "Table of Contents" ) : string
sectionId string
tocPageTitle string
return string
		/// <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>
		/// 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 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 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;
		}