OneNoteConversionTool.OutputGenerator.OneNoteGenerator.GetPageWidth C# (CSharp) 메소드

GetPageWidth() 공개 메소드

Get the height of the page
public GetPageWidth ( string pageId ) : double
pageId string id of the page
리턴 double
		public double GetPageWidth(string pageId)
		{
			double retVal = 520.0;

			XmlDocument xmlPageDoc = GetPageContent(pageId);
			XmlNodeList nodeList = xmlPageDoc.SelectNodes("//*[one:Position]", GetNSManager(xmlPageDoc.NameTable));
			if (nodeList != null)
			{
				foreach (XmlNode node in nodeList)
				{
					XmlElement xmlPosition = node["one:Position"];
					XmlElement xmlSize = node["one:Size"];
					if (xmlPosition == null || xmlSize == null) continue;

					XmlAttribute xmlWidth = xmlSize.Attributes["width"];

					double width = xmlWidth == null ? 0 : Double.Parse(xmlWidth.Value);

					retVal = Math.Max(retVal, width);
				}
			}

			return retVal;
		}

Usage Example

		/// <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;
		}