Exemplo n.º 1
0
        private void PDFExportPage(string basedName, Data.ONPage page)
        {
            if (page == null)
            {
                throw new ArgumentNullException("page");
            }

            string fileName = Path.Combine(basedName, page.ID);

            fileName        += ".pdf";
            page.PDFFilePath = fileName;

            if (File.Exists(fileName))
            {
                if (File.GetCreationTime(fileName) == page.LastModifiedTime)
                {
                    // this page is not modified since last update
                    return;
                }
                else
                {
                    // delete existing file
                    File.Delete(fileName);
                }
            }
            Log.Verbose(string.Format("Exporting page [{0}] to PDF", page.Name));
            OneNoteApplication.Publish(page.ID, fileName, OneNote.PublishFormat.pfPDF, string.Empty);
            File.SetCreationTime(fileName, page.LastModifiedTime);
            File.SetLastWriteTime(fileName, page.LastModifiedTime);
        }
Exemplo n.º 2
0
        private string GetPageXml(string pageID)
        {
            string pageXml;

            OneNoteApplication.GetPageContent(pageID, out pageXml, PageInfo.piSelection);

            return(pageXml);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 插入 HighLight Code 至滑鼠游標的位置
        /// Insert HighLight Code To Mouse Position
        /// </summary>
        private void InsertHighLightCodeToCurrentSide(string fileName, string pageXml, HighLightParameter parameters, XElement outline, bool selectedTextFormated)
        {
            try
            {
                // Trace.TraceInformation(System.Reflection.MethodBase.GetCurrentMethod().Name);
                string htmlContent = File.ReadAllText(fileName, new UTF8Encoding(false));

                string byteOrderMarkUtf8 = Encoding.UTF8.GetString(Encoding.UTF8.GetPreamble());
                htmlContent = htmlContent.Replace(byteOrderMarkUtf8, "");

                var pageNode = GetPageNode();

                if (pageNode != null)
                {
                    var      existingPageId = pageNode.Attribute("ID").Value;
                    string[] position       = null;
                    if (outline == null)
                    {
                        position = GetMousePointPosition(pageXml);
                    }

                    var page = InsertHighLightCode(htmlContent, position, parameters, outline, (new GenerateHighLight()).Config, selectedTextFormated, IsSelectedTextInline(pageXml));
                    page.Root.SetAttributeValue("ID", existingPageId);

                    //Bug fix - remove overflow value for Indents
                    foreach (var el in page.Descendants(ns + "Indent").Where(n => double.Parse(n.Attribute("indent").Value, new CultureInfo(page.Root.Attribute("lang").Value)) > 1000000))
                    {
                        el.Attribute("indent").Value = "0";
                    }

                    OneNoteApplication.UpdatePageContent(page.ToString(), DateTime.MinValue);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("Exception from InsertHighLightCodeToCurrentSide: " + e.ToString());
            }
        }
Exemplo n.º 4
0
        XElement GetPageNode()
        {
            string notebookXml;

            try
            {
                OneNoteApplication.GetHierarchy(null, HierarchyScope.hsPages, out notebookXml, XMLSchema.xs2013);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Exception from onApp.GetHierarchy:" + ex.Message);
                return(null);;
            }

            var doc = XDocument.Parse(notebookXml);

            ns = doc.Root.Name.Namespace;

            var pageNode = doc.Descendants(ns + "Page")
                           .Where(n => n.Attribute("isCurrentlyViewed") != null && n.Attribute("isCurrentlyViewed").Value == "true")
                           .FirstOrDefault();

            return(pageNode);
        }