public virtual void CustomDestinationPrefixTest() { IDictionary <String, int?> priorityMappings = new Dictionary <String, int?>(); priorityMappings.Put("p", 1); OutlineHandler outlineHandler = new OutlineHandler().PutAllTagPriorityMappings(priorityMappings); outlineHandler.SetDestinationNamePrefix("prefix-"); NUnit.Framework.Assert.AreEqual("prefix-", outlineHandler.GetDestinationNamePrefix()); ProcessorContext context = new ProcessorContext(new ConverterProperties().SetOutlineHandler(outlineHandler )); context.Reset(new PdfDocument(new PdfWriter(new MemoryStream()))); IElementNode elementNode = new JsoupElementNode(new iText.StyledXmlParser.Jsoup.Nodes.Element(iText.StyledXmlParser.Jsoup.Parser.Tag .ValueOf(TagConstants.P), TagConstants.P)); IDictionary <String, String> styles = new Dictionary <String, String>(); styles.Put(CssConstants.WHITE_SPACE, CssConstants.NORMAL); styles.Put(CssConstants.TEXT_TRANSFORM, CssConstants.LOWERCASE); // Styles are required in the constructor of the PTagWorker class elementNode.SetStyles(styles); outlineHandler.AddOutlineAndDestToDocument(new PTagWorker(elementNode, context), elementNode, context); PdfOutline pdfOutline = context.GetPdfDocument().GetOutlines(false).GetAllChildren()[0]; NUnit.Framework.Assert.AreEqual("p1", pdfOutline.GetTitle()); PdfString pdfStringDest = (PdfString)pdfOutline.GetDestination().GetPdfObject(); NUnit.Framework.Assert.AreEqual("prefix-1", pdfStringDest.ToUnicodeString()); }
// This recursive method calls itself if an examined bookmark entry has kids. // The method writes bookmark title to the passed list private void AddTitle(PdfOutline outline, List <String> result) { String bookmarkTitle = outline.GetTitle(); result.Add(bookmarkTitle); IList <PdfOutline> kids = outline.GetAllChildren(); if (kids != null) { foreach (PdfOutline kid in kids) { AddTitle(kid, result); } } }
protected void GetBookmark(PdfOutline outline, IDictionary <string, PdfObject> names, PdfDocument pdfDoc) { if (outline.GetDestination() != null) { BookItem bookItem; bookItem.title = outline.GetTitle(); PdfObject pageNumber = outline.GetDestination() .GetDestinationPage(names); bookItem.page = pdfDoc.GetPageNumber(pdfDoc.GetPage((PdfDictionary)pageNumber)).ToString(); _outline.Add(bookItem); } foreach (PdfOutline child in outline.GetAllChildren()) { GetBookmark(child, names, pdfDoc); } }
public void listOutline(PdfDocument pdfDoc, PdfOutline outline) { logMsgFmtln("bookmark| depth", formatBookmark(outline.GetTitle(), depth, outline.GetPageNumber(pdfDoc))); IList <PdfOutline> kids = outline.GetAllChildren(); if (kids.Count != 0) { depth++; for (int i = 0; i < kids.Count; i++) { listOutline(pdfDoc, kids[i]); } depth--; } }
private void addExistBookmark2(PdfOutline destOutline, List <MergeItem> mergeTreeList, int depth) { int pageNumber = destOutline.GetPageNumber(destPdf); List <MergeItem> newMergeTreeList = new List <MergeItem>(1); mergeTreeList.Add(new MergeItem(destOutline.GetTitle(), LEAF, newMergeTreeList, pageNumber, depth, new FileItem())); IList <PdfOutline> children = destOutline.GetAllChildren(); if (children.Count > 0) { foreach (PdfOutline child in children) { addExistBookmark2(child, newMergeTreeList, depth + 1); } } }
private static void ListBookmarks(PdfOutline outline, IDictionary <String, PdfObject> names, PdfDocument document, List <Bookmark> bookmarks, int level, Guid parentId) { Bookmark mark = null; if (outline.GetDestination() != null) { mark = new Bookmark(outline.GetTitle(), document.GetPageNumber((PdfDictionary)outline.GetDestination().GetDestinationPage(names))); mark.Level = level; mark.ParentId = parentId; bookmarks.Add(mark); parentId = mark.Id; } level++; foreach (PdfOutline child in outline.GetAllChildren()) { ListBookmarks(child, names, document, bookmarks, level, parentId); } }