Esempio n. 1
0
        private ONSection GetSubSection(ONSection section, string sectionName)
        {
            string realSName;
            string extra;

            SplitPath(sectionName, out realSName, out extra);

            try
            {
                ONSection results = (from subSection in section.SubSections
                                     where realSName.ToLower() == subSection.Name.ToLower()
                                     select subSection).First();

                if (string.IsNullOrEmpty(extra))
                {
                    return(results);
                }
                else
                {
                    return(GetSubSection(results, extra));
                }
            }
            catch (InvalidOperationException)
            {
                // The source sequence is empty.
                return(null);
            }
            catch (ArgumentNullException)
            {
                return(null);
            }
        }
Esempio n. 2
0
 private void SetExcludeSection(ONNotebook notebook)
 {
     // set sections to exclude
     foreach (string s in Config.Current.ExcludeSections)
     {
         Data.ONSection exSec = notebook.GetSection(s);
         if (exSec != null)
         {
             Log.Information(string.Format("Exclude section [{0}] from exporting", exSec.Name));
             exSec.Exclude = true;
         }
     }
 }
Esempio n. 3
0
        private void PDFCombineSection(PdfOutline parent,
                                       Data.ONSection section)
        {
            if (section == null)
            {
                throw new ArgumentNullException("section");
            }
            if (section.Exclude)
            {
                return;
            }

            PdfOutline gotoPage = null;

            int       currentPage = (pdfWriter.CurrentPageNumber == 1) ? pdfWriter.CurrentPageNumber : (pdfWriter.CurrentPageNumber + 1);
            PdfAction action      = PdfAction.GotoLocalPage(currentPage, new PdfDestination(PdfDestination.FITH, 806), pdfWriter);

            gotoPage = new PdfOutline(parent, action, section.Name);
            pdfWriter.DirectContent.AddOutline(gotoPage);

            foreach (Data.ONSection subSection in section.SubSections)
            {
                if (!subSection.Exclude)
                {
                    TOCHandler.AddTocEntry(subSection.Name, pdfWriter.CurrentPageNumber);

                    TOCHandler.BeginTocEntry();
                    PDFCombineSection(gotoPage, subSection);
                    TOCHandler.EndTocEntry();
                }
            }
            foreach (Data.ONPage page in section.Pages)
            {
                if (pdfWriter.CurrentPageNumber == 1)
                {
                    TOCHandler.AddTocEntry(page.Name, pdfWriter.CurrentPageNumber);
                }
                else
                {
                    TOCHandler.AddTocEntry(page.Name, pdfWriter.CurrentPageNumber + 1);
                }
                PDFCombinePage(gotoPage, page);
            }
        }
Esempio n. 4
0
        public void SetSectionExcludeFlag(ONSection section, bool isExclude)
        {
            if (section == null)
            {
                return;
            }

            Queue <ONSection> queue = new Queue <ONSection>();

            queue.Enqueue(section);
            while (queue.Count > 0)
            {
                ONSection s = queue.Dequeue();
                s.Exclude = isExclude;
                foreach (ONSection ss in s.SubSections)
                {
                    queue.Enqueue(ss);
                }
            }
        }
Esempio n. 5
0
        private void PDFExportSection(string basedName, Data.ONSection section)
        {
            if (section == null)
            {
                throw new ArgumentNullException("section");
            }

            string baseDir = Path.Combine(basedName, section.Name);

            Directory.CreateDirectory(baseDir);
            // now export sub sections
            foreach (Data.ONSection subSection in section.SubSections)
            {
                if (!subSection.Exclude)
                {
                    PDFExportSection(baseDir, subSection);
                }
            }
            // now export pages
            foreach (Data.ONPage page in section.Pages)
            {
                PDFExportPage(baseDir, page);
            }
        }
Esempio n. 6
0
        static void Main(string[] args)
        {
            OneNote.Application oneApp;
            // Obtain reference to OneNote application
            try
            {
                oneApp = new OneNote.Application();
            }
            catch (Exception e)
            {
                Log.Error(string.Format("Could not obtain reference to OneNote ({0})", e.Message));
                return;
            }

            // get till page level
            oneApp.GetHierarchy(null, OneNote.HierarchyScope.hsPages, out string outputXML);
            ONNotebookListing onListing = new ONNotebookListing(outputXML);

            if (Config.Current.ShowHelp || Config.Current.Arguments.Count == 0)
            {
                HelpHandler hh = new HelpHandler();
                Log.Information(hh.Print());
                return;
            }

            if (Config.Current.ListAllNotebook)
            {
                string[] notebookNames = onListing.ListAllNotebook();
                foreach (var nb in notebookNames)
                {
                    Console.WriteLine(nb);
                }
                return;
            }

            if (!string.IsNullOrEmpty(Config.Current.NotebookName))
            {
                Log.Information("Query notebook information");
                ONNotebook notebook = onListing.GetNotebook(Config.Current.NotebookName);
                if (notebook == null)
                {
                    Log.Error("Cannot get desired notebook");
                    return;
                }
                Log.Information(string.Format("Notebook name: {0}", notebook.Name));
                Log.Information(string.Format("Notebook ID: {0}", notebook.ID));
                Log.Information(string.Format("Number section: {0}", notebook.Sections.Count));

                Log.Information("Begin exporting ...");

                Export2PDF export2PDF = new Export2PDF();
                export2PDF.BasedPath          = Config.Current.CacheFolder;
                export2PDF.OneNoteApplication = oneApp;

                export2PDF.CreateCacheFolder(notebook);

                if (Config.Current.ExportNotebook)
                {
                    Log.Information(string.Format("Exporting entire notebook [{0}]", notebook.Name));
                    export2PDF.Export(Config.Current.OutputPath, notebook);
                }
                if (!string.IsNullOrEmpty(Config.Current.ExportSection))
                {
                    OneNote2PDF.Library.Data.ONSection section = notebook.GetSection(Config.Current.ExportSection);
                    if (section == null)
                    {
                        Log.Error("Cannot find the specified section");
                    }
                    else
                    {
                        Log.Information(string.Format("Exporting section [{0}] ...", section.Name));
                        export2PDF.Export(Config.Current.OutputPath, section);
                    }
                }
                return;
            }
        }