Ejemplo n.º 1
0
        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());
        }
Ejemplo n.º 2
0
        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);
            }
        }
Ejemplo n.º 3
0
        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);
            }
        }