Ejemplo n.º 1
0
        // Loop through all the pages in the document creating bookmark items for them
        private static void loadBookmarks(Document activeDocument, ref List <PDFBookmark> bookmarks, Hashtable options)
        {
            var pages = activeDocument.Pages;

            if (pages.Count > 0)
            {
                // Create a top-level bookmark
                var parentBookmark = new PDFBookmark();
                parentBookmark.title    = (string)options["original_basename"];
                parentBookmark.page     = 1;
                parentBookmark.children = new List <PDFBookmark>();

                foreach (var p in pages)
                {
                    var bookmark = new PDFBookmark();
                    bookmark.page  = ((Page)p).PageIndex;
                    bookmark.title = ((Page)p).Name;
                    parentBookmark.children.Add(bookmark);
                    Converter.releaseCOMObject(p);
                }
                Converter.releaseCOMObject(pages);
                bookmarks.Add(parentBookmark);
            }
        }
Ejemplo n.º 2
0
        // Loop through all the slides in the presentation creating bookmark items
        // for all the slides that are not hidden
        private static void loadBookmarks(Presentation activePresentation, ref List <PDFBookmark> bookmarks)
        {
            var slides = activePresentation.Slides;

            if (slides.Count > 0)
            {
                var page = 1;

                // Create a top-level bookmark
                var parentBookmark = new PDFBookmark();
                parentBookmark.title    = activePresentation.Name;
                parentBookmark.page     = 1;
                parentBookmark.children = new List <PDFBookmark>();

                // Loop through the slides, adding a ToC entry to the top-level bookmark
                foreach (var s in slides)
                {
                    // Look at the transition on the slide to determine if it is hidden
                    var trans = ((Slide)s).SlideShowTransition;
                    if (trans.Hidden == MSCore.MsoTriState.msoCTrue || trans.Hidden == MSCore.MsoTriState.msoTrue)
                    {
                        Converter.releaseCOMObject(trans);
                        Converter.releaseCOMObject(s);
                        continue;
                    }
                    Converter.releaseCOMObject(trans);

                    // Create a new bookmark and add the page
                    var bookmark = new PDFBookmark();
                    bookmark.page = page++;

                    // Work out a title - base this on the slide name and any title shape text
                    var slideName = ((Slide)s).Name;
                    var shapes    = ((Slide)s).Shapes;

                    // See if there is a title in the slides shapes
                    if (shapes.HasTitle == MSCore.MsoTriState.msoTrue || shapes.HasTitle == MSCore.MsoTriState.msoCTrue)
                    {
                        var shapeTitle = shapes.Title;
                        if (shapeTitle != null && (shapeTitle.HasTextFrame == MSCore.MsoTriState.msoCTrue || shapeTitle.HasTextFrame == MSCore.MsoTriState.msoTrue))
                        {
                            var textframe = shapeTitle.TextFrame;
                            if (textframe != null && (textframe.HasText == MSCore.MsoTriState.msoTrue || textframe.HasText == MSCore.MsoTriState.msoCTrue))
                            {
                                var textrange = textframe.TextRange;
                                if (!String.IsNullOrWhiteSpace(textrange.TrimText().Text))
                                {
                                    slideName = textrange.TrimText().Text;
                                }
                                Converter.releaseCOMObject(textrange);
                            }
                            Converter.releaseCOMObject(textframe);
                        }
                        Converter.releaseCOMObject(shapeTitle);
                    }
                    Converter.releaseCOMObject(shapes);

                    bookmark.title = String.Format("Page {0} - {1}", bookmark.page, slideName);

                    // Put the bookmark into our parent bookmark children
                    parentBookmark.children.Add(bookmark);

                    // Clean up the references to the slide
                    Converter.releaseCOMObject(s);
                }
                // Add the top-level bookmark which will be passed back to the main program
                bookmarks.Add(parentBookmark);
            }
            Converter.releaseCOMObject(slides);
        }