예제 #1
0
파일: PDFHelper.cs 프로젝트: jehan2898/root
        internal static bool AddBookmarkTooutline(PDFBookmarkItem bookmarentry, PDDocument document, PDOutlineItem outline)
        {
            bool flag;

            try
            {
                if (bookmarentry.BookMarkPage <= document.getNumberOfPages())
                {
                    PDPage page = document.getPage(bookmarentry.BookMarkPage - 1);
                    PDPageFitWidthDestination pDPageFitWidthDestination = new PDPageFitWidthDestination();
                    pDPageFitWidthDestination.setPage(page);
                    outline.setDestination(pDPageFitWidthDestination);
                    outline.setTitle(bookmarentry.BookmarkTitle);
                }
                if ((bookmarentry.BookmarkItems == null ? false : bookmarentry.BookmarkItems.Count > 0))
                {
                    foreach (PDFBookmarkItem bookmarkItem in bookmarentry.BookmarkItems)
                    {
                        PDOutlineItem pDOutlineItem = new PDOutlineItem();
                        PDFHelper.AddBookmarkTooutline(bookmarkItem, document, pDOutlineItem);
                        outline.addLast(pDOutlineItem);
                    }
                }
                flag = true;
            }
            catch (Exception exception)
            {
                flag = false;
            }
            return(flag);
        }
예제 #2
0
        internal PDFBookmarkItem(PDOutlineItem pdfBoxBookmark, PDDocument doc)
        {
            this.PDFBoxBookmark = pdfBoxBookmark;
            PDPage pDPage = pdfBoxBookmark.findDestinationPage(doc);

            this.BookMarkPage  = doc.getPages().indexOf(pDPage) + 1;
            this.bookmarkTitle = pdfBoxBookmark.getTitle();
            this.BookmarkItems = new List <PDFBookmarkItem>();
        }
예제 #3
0
파일: PDFHelper.cs 프로젝트: jehan2898/root
        internal static void addBookmark(PDOutlineItem bookmarkItem, List <PDFBookmarkItem> bookmarks, PDDocument doc)
        {
            PDOutlineItem   firstChild      = bookmarkItem.getFirstChild();
            PDFBookmarkItem pDFBookmarkItem = new PDFBookmarkItem(bookmarkItem, doc);

            bookmarks.Add(pDFBookmarkItem);
            while (firstChild != null)
            {
                PDFHelper.addBookmark(firstChild, pDFBookmarkItem.BookmarkItems, doc);
                firstChild = firstChild.getNextSibling();
            }
        }
예제 #4
0
 public void SplitByTopLevelBookmarks()
 {
     if (this.CheckOutput())
     {
         PDFHelper.DisplayTrialPopupIfNecessary();
         try
         {
             PDDocumentCatalog documentCatalog = this.pdfDocument.PDFBoxDocument.getDocumentCatalog();
             PDDocumentOutline documentOutline = documentCatalog.getDocumentOutline();
             if (documentOutline != null)
             {
                 PDOutlineItem firstChild = documentOutline.getFirstChild();
                 PDPageTree    pages      = documentCatalog.getPages();
                 List <int>    nums       = new List <int>();
                 while (firstChild != null)
                 {
                     PDPage pDPage = firstChild.findDestinationPage(this.pdfDocument.PDFBoxDocument);
                     nums.Add(pages.indexOf(pDPage));
                     firstChild = firstChild.getNextSibling();
                 }
                 nums.Add(pages.getCount());
                 for (int i = 0; i < nums.Count - 1; i++)
                 {
                     int        item       = nums[i];
                     int        num        = nums[i + 1];
                     PDDocument pDDocument = new PDDocument();
                     for (int j = item; j < num; j++)
                     {
                         pDDocument.addPage(this.pdfDocument.PDFBoxDocument.getPage(j));
                     }
                     pDDocument = PDFHelper.AddTrialStampIfNecessary(pDDocument);
                     string str = string.Format("{0} [{1}].pdf", this.OutputFileName, i);
                     pDDocument.save(Path.Combine(this.OutputFilePath, str));
                     pDDocument.close();
                 }
             }
             else
             {
                 Console.WriteLine("This document does not contain any bookmarks.");
             }
         }
         catch (Exception exception1)
         {
             Exception exception = exception1;
             throw new PDFToolkitException(exception.Message, exception.InnerException);
         }
     }
 }
예제 #5
0
        public bool AddBookmarks(PDFBookmark bookmarks)
        {
            bool flag;

            try
            {
                PDDocumentOutline pDDocumentOutline = new PDDocumentOutline();
                this.PDFBoxDocument.getDocumentCatalog().setDocumentOutline(pDDocumentOutline);
                foreach (PDFBookmarkItem bookmarkItem in bookmarks.BookmarkItems)
                {
                    PDOutlineItem pDOutlineItem = new PDOutlineItem();
                    PDFHelper.AddBookmarkTooutline(bookmarkItem, this.PDFBoxDocument, pDOutlineItem);
                    pDDocumentOutline.addLast(pDOutlineItem);
                }
                pDDocumentOutline.openNode();
                flag = true;
            }
            catch (Exception exception)
            {
                flag = false;
            }
            return(flag);
        }