public virtual void DocWithInvalidMapping06()
        {
            PdfDocument pdfDocument = new PdfDocument(new PdfWriter(destinationFolder + "docWithInvalidMapping06.pdf",
                                                                    new WriterProperties().SetPdfVersion(PdfVersion.PDF_2_0)));

            pdfDocument.SetTagged();
            Document            document  = new Document(pdfDocument);
            TagStructureContext tagCntxt  = pdfDocument.GetTagStructureContext();
            PdfNamespace        pointerNs = tagCntxt.FetchNamespace(StandardNamespaces.PDF_2_0);

            pointerNs.AddNamespaceRoleMapping(LayoutTaggingPdf2Test.HtmlRoles.span, StandardRoles.SPAN, pointerNs);
            // deliberately creating namespace via constructor instead of using TagStructureContext#fetchNamespace
            PdfNamespace stdNs2 = new PdfNamespace(StandardNamespaces.PDF_2_0);

            stdNs2.AddNamespaceRoleMapping(LayoutTaggingPdf2Test.HtmlRoles.span, StandardRoles.EM, stdNs2);
            Text customRolePText1 = new Text("Hello world text 1.");

            customRolePText1.GetAccessibilityProperties().SetRole(LayoutTaggingPdf2Test.HtmlRoles.span);
            customRolePText1.GetAccessibilityProperties().SetNamespace(stdNs2);
            document.Add(new Paragraph(customRolePText1));
            Text customRolePText2 = new Text("Hello world text 2.");

            customRolePText2.GetAccessibilityProperties().SetRole(LayoutTaggingPdf2Test.HtmlRoles.span);
            // not explicitly setting namespace that we've manually created. This will lead to the situation, when
            // /Namespaces entry in StructTreeRoot would have two different namespace dictionaries with the same name.
            document.Add(new Paragraph(customRolePText2));
            document.Close();
            CompareResult("docWithInvalidMapping06");
        }
        public virtual void CustomRolesMappingPdf2()
        {
            PdfDocument pdfDocument = new PdfDocument(new PdfWriter(destinationFolder + "customRolesMappingPdf2.pdf",
                                                                    new WriterProperties().SetPdfVersion(PdfVersion.PDF_2_0)));

            pdfDocument.SetTagged();
            TagStructureContext tagsContext   = pdfDocument.GetTagStructureContext();
            PdfNamespace        stdNamespace2 = tagsContext.FetchNamespace(StandardNamespaces.PDF_2_0);
            PdfNamespace        xhtmlNs       = new PdfNamespace("http://www.w3.org/1999/xhtml");
            PdfNamespace        html4Ns       = new PdfNamespace("http://www.w3.org/TR/html4");
            String h9  = "H9";
            String h11 = "H11";

            // deliberately mapping to H9 tag
            xhtmlNs.AddNamespaceRoleMapping(LayoutTaggingPdf2Test.HtmlRoles.h1, h9, stdNamespace2);
            xhtmlNs.AddNamespaceRoleMapping(LayoutTaggingPdf2Test.HtmlRoles.p, StandardRoles.P, stdNamespace2);
            xhtmlNs.AddNamespaceRoleMapping(LayoutTaggingPdf2Test.HtmlRoles.img, StandardRoles.FIGURE, stdNamespace2);
            xhtmlNs.AddNamespaceRoleMapping(LayoutTaggingPdf2Test.HtmlRoles.ul, StandardRoles.L, stdNamespace2);
            xhtmlNs.AddNamespaceRoleMapping(StandardRoles.SPAN, LayoutTaggingPdf2Test.HtmlRoles.span, xhtmlNs);
            xhtmlNs.AddNamespaceRoleMapping(LayoutTaggingPdf2Test.HtmlRoles.span, StandardRoles.SPAN, stdNamespace2);
            xhtmlNs.AddNamespaceRoleMapping(LayoutTaggingPdf2Test.HtmlRoles.center, StandardRoles.P, stdNamespace2);
            html4Ns.AddNamespaceRoleMapping(LayoutTaggingPdf2Test.HtmlRoles.center, LayoutTaggingPdf2Test.HtmlRoles.center
                                            , xhtmlNs);
            // test some tricky mapping cases
            stdNamespace2.AddNamespaceRoleMapping(h9, h11, stdNamespace2);
            stdNamespace2.AddNamespaceRoleMapping(h11, h11, stdNamespace2);
            tagsContext.GetAutoTaggingPointer().SetNamespaceForNewTags(xhtmlNs);
            Document document = new Document(pdfDocument);

            AddContentToDocInCustomNs(pdfDocument, stdNamespace2, xhtmlNs, html4Ns, h11, document);
            document.Close();
            CompareResult("customRolesMappingPdf2");
        }
        public virtual void DocWithExplicitAndImplicitDefaultNsAtTheSameTime()
        {
            PdfDocument pdfDocument = new PdfDocument(new PdfWriter(destinationFolder + "docWithExplicitAndImplicitDefaultNsAtTheSameTime.pdf"
                                                                    , new WriterProperties().SetPdfVersion(PdfVersion.PDF_2_0)));

            pdfDocument.SetTagged();
            TagStructureContext tagsContext = pdfDocument.GetTagStructureContext();

            tagsContext.SetDocumentDefaultNamespace(null);
            PdfNamespace explicitDefaultNs = tagsContext.FetchNamespace(StandardNamespaces.PDF_1_7);
            Document     document          = new Document(pdfDocument);
            Paragraph    hPara             = new Paragraph("This is header.");

            hPara.GetAccessibilityProperties().SetRole(StandardRoles.H);
            hPara.GetAccessibilityProperties().SetNamespace(explicitDefaultNs);
            document.Add(hPara);
            PdfNamespace xhtmlNs = new PdfNamespace("http://www.w3.org/1999/xhtml");

            xhtmlNs.AddNamespaceRoleMapping(LayoutTaggingPdf2Test.HtmlRoles.img, StandardRoles.FIGURE, explicitDefaultNs
                                            );
            xhtmlNs.AddNamespaceRoleMapping(LayoutTaggingPdf2Test.HtmlRoles.ul, StandardRoles.L);
            iText.Layout.Element.Image img = new Image(ImageDataFactory.Create(sourceFolder + imageName)).SetWidth(100
                                                                                                                   );
            img.GetAccessibilityProperties().SetRole(LayoutTaggingPdf2Test.HtmlRoles.img);
            img.GetAccessibilityProperties().SetNamespace(xhtmlNs);
            document.Add(img);
            List list = new List().SetListSymbol("-> ");

            list.GetAccessibilityProperties().SetRole(LayoutTaggingPdf2Test.HtmlRoles.ul);
            list.GetAccessibilityProperties().SetNamespace(xhtmlNs);
            list.Add("list item").Add("list item").Add("list item").Add("list item").Add("list item");
            document.Add(list);
            xhtmlNs.AddNamespaceRoleMapping(LayoutTaggingPdf2Test.HtmlRoles.center, "Center", explicitDefaultNs);
            xhtmlNs.AddNamespaceRoleMapping(LayoutTaggingPdf2Test.HtmlRoles.p, "Note", explicitDefaultNs);
            explicitDefaultNs.AddNamespaceRoleMapping("Center", StandardRoles.P, explicitDefaultNs);
            explicitDefaultNs.AddNamespaceRoleMapping("Note", "Note");
            xhtmlNs.AddNamespaceRoleMapping(LayoutTaggingPdf2Test.HtmlRoles.span, "Note");
            pdfDocument.GetStructTreeRoot().AddRoleMapping("Note", StandardRoles.P);
            Paragraph centerPara = new Paragraph("centered text");

            centerPara.GetAccessibilityProperties().SetRole(LayoutTaggingPdf2Test.HtmlRoles.center);
            centerPara.GetAccessibilityProperties().SetNamespace(xhtmlNs);
            Text simpleSpan = new Text("simple p with simple span");

            simpleSpan.GetAccessibilityProperties().SetRole(LayoutTaggingPdf2Test.HtmlRoles.span);
            simpleSpan.GetAccessibilityProperties().SetNamespace(xhtmlNs);
            Paragraph simplePara = new Paragraph(simpleSpan);

            simplePara.GetAccessibilityProperties().SetRole(LayoutTaggingPdf2Test.HtmlRoles.p);
            simplePara.GetAccessibilityProperties().SetNamespace(xhtmlNs);
            document.Add(centerPara).Add(simplePara);
            pdfDocument.GetStructTreeRoot().AddRoleMapping("I", StandardRoles.SPAN);
            Text iSpan = new Text("cursive span");

            iSpan.GetAccessibilityProperties().SetRole("I");
            document.Add(new Paragraph(iSpan));
            document.Close();
            CompareResult("docWithExplicitAndImplicitDefaultNsAtTheSameTime");
        }
        public virtual void StampTest05()
        {
            PdfDocument pdfDocument = new PdfDocument(new PdfReader(sourceFolder + "simpleDocNewStdNs.pdf"), new PdfWriter
                                                          (destinationFolder + "stampTest05.pdf", new WriterProperties().SetPdfVersion(PdfVersion.PDF_2_0)));
            TagStructureContext tagCntxt = pdfDocument.GetTagStructureContext();
            PdfNamespace        xhtmlNs  = tagCntxt.FetchNamespace("http://www.w3.org/1999/xhtml");
            PdfNamespace        ssn2     = tagCntxt.FetchNamespace(StandardNamespaces.PDF_2_0);

            xhtmlNs.AddNamespaceRoleMapping(LayoutTaggingPdf2Test.HtmlRoles.ul, StandardRoles.L, ssn2);
            TagTreePointer pointer = new TagTreePointer(pdfDocument);

            pointer.MoveToKid(StandardRoles.TABLE).MoveToKid(StandardRoles.TR).MoveToKid(1, StandardRoles.TD).MoveToKid
                (StandardRoles.L);
            pointer.SetRole(LayoutTaggingPdf2Test.HtmlRoles.ul).GetProperties().SetNamespace(xhtmlNs);
            pdfDocument.Close();
            CompareResult("stampTest05");
        }
        public virtual void DocWithInvalidMapping09()
        {
            PdfDocument pdfDocument = new PdfDocument(new PdfWriter(destinationFolder + "docWithInvalidMapping09.pdf",
                                                                    new WriterProperties().SetPdfVersion(PdfVersion.PDF_2_0)));

            pdfDocument.SetTagged();
            TagStructureContext tagsContext = pdfDocument.GetTagStructureContext();
            PdfNamespace        ssn2        = tagsContext.FetchNamespace(StandardNamespaces.PDF_2_0);

            ssn2.AddNamespaceRoleMapping(StandardRoles.DOCUMENT, "Book", ssn2);
            Document document = new Document(pdfDocument);

            document.Add(new Paragraph("hello world; root tag mapping"));
            document.Close();
            CompareResult("docWithInvalidMapping09");
        }
 public virtual void DocWithInvalidMapping02()
 {
     NUnit.Framework.Assert.That(() => {
         PdfDocument pdfDocument = new PdfDocument(new PdfWriter(destinationFolder + "docWithInvalidMapping02.pdf",
                                                                 new WriterProperties().SetPdfVersion(PdfVersion.PDF_2_0)));
         pdfDocument.SetTagged();
         TagStructureContext tagsContext = pdfDocument.GetTagStructureContext();
         tagsContext.SetDocumentDefaultNamespace(null);
         PdfNamespace explicitDefaultNs = tagsContext.FetchNamespace(StandardNamespaces.PDF_1_7);
         Document document = new Document(pdfDocument);
         explicitDefaultNs.AddNamespaceRoleMapping(LayoutTaggingPdf2Test.HtmlRoles.p, StandardRoles.P);
         Paragraph customRolePara = new Paragraph("Hello world text.");
         customRolePara.GetAccessibilityProperties().SetRole(LayoutTaggingPdf2Test.HtmlRoles.p);
         document.Add(customRolePara);
         document.Close();
     }
                                 , NUnit.Framework.Throws.InstanceOf <PdfException>().With.Message.EqualTo(String.Format(PdfException.RoleIsNotMappedToAnyStandardRole, "p")))
     ;
 }
        public virtual void DocWithInvalidMapping04()
        {
            // TODO this test passes, however it seems, that mingling two standard namespaces in the same tag structure tree should be illegal
            // May be this should be checked if we would implement conforming PDF/UA docs generations in a way PDF/A docs are generated
            PdfDocument pdfDocument = new PdfDocument(new PdfWriter(destinationFolder + "docWithInvalidMapping04.pdf",
                                                                    new WriterProperties().SetPdfVersion(PdfVersion.PDF_2_0)));

            pdfDocument.SetTagged();
            TagStructureContext tagsCntxt = pdfDocument.GetTagStructureContext();
            PdfNamespace        stdNs2    = tagsCntxt.FetchNamespace(StandardNamespaces.PDF_2_0);

            stdNs2.AddNamespaceRoleMapping(LayoutTaggingPdf2Test.HtmlRoles.p, StandardRoles.P);
            Document  document       = new Document(pdfDocument);
            Paragraph customRolePara = new Paragraph("Hello world text.");

            customRolePara.GetAccessibilityProperties().SetRole(LayoutTaggingPdf2Test.HtmlRoles.p);
            document.Add(customRolePara);
            document.Close();
            CompareResult("docWithInvalidMapping04");
        }
        public virtual void SimpleDocExplicitlyOldStdNs()
        {
            PdfDocument pdfDocument = new PdfDocument(new PdfWriter(destinationFolder + "simpleDocExplicitlyOldStdNs.pdf"
                                                                    , new WriterProperties().SetPdfVersion(PdfVersion.PDF_2_0)));

            pdfDocument.SetTagged();
            TagStructureContext tagsContext = pdfDocument.GetTagStructureContext();
            PdfNamespace        @namespace  = tagsContext.FetchNamespace(StandardNamespaces.PDF_1_7);

            tagsContext.SetDocumentDefaultNamespace(@namespace);
            Document  document = new Document(pdfDocument);
            Paragraph h1       = new Paragraph("Header level 1");

            h1.GetAccessibilityProperties().SetRole(StandardRoles.H1);
            Paragraph helloWorldPara = new Paragraph("Hello World from iText7");

            document.Add(h1);
            AddSimpleContentToDoc(document, helloWorldPara);
            document.Close();
            CompareResult("simpleDocExplicitlyOldStdNs");
        }