예제 #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());
        }
        public virtual void LangAttrInDisplayTableForTaggedPdfTest()
        {
            Attributes attributes = new Attributes();

            attributes.Put(AttributeConstants.LANG, "en");
            iText.StyledXmlParser.Jsoup.Nodes.Element element = new iText.StyledXmlParser.Jsoup.Nodes.Element(iText.StyledXmlParser.Jsoup.Parser.Tag
                                                                                                              .ValueOf(TagConstants.DIV), TagConstants.DIV, attributes);
            JsoupElementNode             node   = new JsoupElementNode(element);
            IDictionary <String, String> styles = new Dictionary <String, String>();

            styles.Put(CssConstants.WHITE_SPACE, CssConstants.NORMAL);
            styles.Put(CssConstants.TEXT_TRANSFORM, CssConstants.LOWERCASE);
            styles.Put(CssConstants.DISPLAY, CssConstants.TABLE);
            node.SetStyles(styles);
            ProcessorContext      processorContext = new ProcessorContext(new ConverterProperties());
            DisplayTableTagWorker tagWorker        = new DisplayTableTagWorker(node, processorContext);

            tagWorker.ProcessEnd(node, processorContext);
            IPropertyContainer propertyContainer = tagWorker.GetElementResult();

            NUnit.Framework.Assert.IsTrue(propertyContainer is Table);
            String lang = ((IAccessibleElement)propertyContainer).GetAccessibilityProperties().GetLanguage();

            NUnit.Framework.Assert.AreEqual("en", lang);
        }
예제 #3
0
        public virtual void LangAttrInBrForTaggedPdfTest()
        {
            Attributes attributes = new Attributes();

            attributes.Put(AttributeConstants.LANG, "en");
            iText.StyledXmlParser.Jsoup.Nodes.Element element = new iText.StyledXmlParser.Jsoup.Nodes.Element(iText.StyledXmlParser.Jsoup.Parser.Tag
                                                                                                              .ValueOf(TagConstants.BR), TagConstants.BR, attributes);
            JsoupElementNode             node   = new JsoupElementNode(element);
            IDictionary <String, String> styles = new Dictionary <String, String>();

            styles.Put(CssConstants.FONT_FAMILY, "sans-serif");
            node.SetStyles(styles);
            ProcessorContext   processorContext  = new ProcessorContext(new ConverterProperties());
            BrTagWorker        tagWorker         = new BrTagWorker(node, processorContext);
            IPropertyContainer propertyContainer = tagWorker.GetElementResult();

            NUnit.Framework.Assert.IsTrue(propertyContainer is IAccessibleElement);
            String lang = ((IAccessibleElement)propertyContainer).GetAccessibilityProperties().GetLanguage();

            NUnit.Framework.Assert.AreEqual("en", lang);
        }