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