AddImageToPage() public method

Adds an image to the page The width of the page is at most MaxPageWidth (960 pixels) If the width is bigger, the image is proportionally minimized to MaxPageWidth
public AddImageToPage ( string pageId, Image img, int yPos = 80 ) : void
pageId string
img Image
yPos int
return void
		/// <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 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;
		}