public virtual void AccessibleAttributesInsertionTest01()
        {
            PdfReader      reader   = new PdfReader(sourceFolder + "taggedDocumentWithAttributes.pdf");
            PdfWriter      writer   = new PdfWriter(destinationFolder + "accessibleAttributesInsertionTest01.pdf");
            PdfDocument    document = new PdfDocument(reader, writer);
            TagTreePointer pointer  = new TagTreePointer(document);
            // 2 attributes
            AccessibilityProperties properties = pointer.MoveToKid(0).GetProperties();
            PdfStructureAttributes  testAttr   = new PdfStructureAttributes("test");

            testAttr.AddIntAttribute("N", 4);
            properties.AddAttributes(testAttr);
            testAttr = new PdfStructureAttributes("test");
            testAttr.AddIntAttribute("N", 0);
            properties.AddAttributes(0, testAttr);
            testAttr = new PdfStructureAttributes("test");
            testAttr.AddIntAttribute("N", 5);
            properties.AddAttributes(4, testAttr);
            testAttr = new PdfStructureAttributes("test");
            testAttr.AddIntAttribute("N", 2);
            properties.AddAttributes(2, testAttr);
            try {
                properties.AddAttributes(10, testAttr);
                NUnit.Framework.Assert.Fail();
            }
            catch (Exception e) {
                NUnit.Framework.Assert.IsTrue(ExceptionUtil.IsOutOfRange(e));
            }
            document.Close();
            CompareResult("accessibleAttributesInsertionTest01.pdf", "cmp_accessibleAttributesInsertionTest01.pdf", "diffAttributes01_"
                          );
        }
Exemple #2
0
        public static void ApplyTableAttributes(AbstractRenderer renderer)
        {
            if (!(renderer.GetModelElement() is IAccessibleElement))
            {
                return;
            }
            IAccessibleElement accessibleElement = (IAccessibleElement)renderer.GetModelElement();
            PdfDictionary      attributes        = new PdfDictionary();
            PdfName            attributesType    = PdfName.Table;

            attributes.Put(PdfName.O, attributesType);
            if (accessibleElement is Cell)
            {
                Cell cell = (Cell)accessibleElement;
                if (cell.GetRowspan() != 1)
                {
                    attributes.Put(PdfName.RowSpan, new PdfNumber(cell.GetRowspan()));
                }
                if (cell.GetColspan() != 1)
                {
                    attributes.Put(PdfName.ColSpan, new PdfNumber(cell.GetColspan()));
                }
            }
            if (attributes.Size() > 1)
            {
                AccessibilityProperties properties = accessibleElement.GetAccessibilityProperties();
                RemoveSameAttributesTypeIfPresent(properties, attributesType);
                properties.AddAttributes(attributes);
            }
        }
Exemple #3
0
 public static void ApplyLayoutAttributes(PdfName role, AbstractRenderer renderer, PdfDocument doc) {
     if (!(renderer.GetModelElement() is IAccessibleElement)) {
         return;
     }
     int tagType = PdfStructElem.IdentifyType(doc, role);
     PdfDictionary attributes = new PdfDictionary();
     PdfName attributesType = PdfName.Layout;
     attributes.Put(PdfName.O, attributesType);
     PdfDictionary roleMap = doc.GetStructTreeRoot().GetRoleMap();
     if (roleMap.ContainsKey(role)) {
         role = roleMap.GetAsName(role);
     }
     //TODO WritingMode attribute applying when needed
     ApplyCommonLayoutAttributes(renderer, attributes);
     if (tagType == PdfStructElem.BlockLevel) {
         ApplyBlockLevelLayoutAttributes(role, renderer, attributes, doc);
     }
     if (tagType == PdfStructElem.InlineLevel) {
         ApplyInlineLevelLayoutAttributes(renderer, attributes);
     }
     if (tagType == PdfStructElem.Illustration) {
         ApplyIllustrationLayoutAttributes(renderer, attributes);
     }
     if (attributes.Size() > 1) {
         AccessibilityProperties properties = ((IAccessibleElement)renderer.GetModelElement()).GetAccessibilityProperties
             ();
         RemoveSameAttributesTypeIfPresent(properties, attributesType);
         properties.AddAttributes(attributes);
     }
 }
Exemple #4
0
        public static void ApplyListAttributes(AbstractRenderer renderer)
        {
            if (!(renderer.GetModelElement() is List))
            {
                return;
            }
            PdfDictionary attributes     = new PdfDictionary();
            PdfName       attributesType = PdfName.List;

            attributes.Put(PdfName.O, attributesType);
            Object listSymbol = renderer.GetProperty <Object>(Property.LIST_SYMBOL);

            if (listSymbol is ListNumberingType)
            {
                ListNumberingType numberingType = (ListNumberingType)listSymbol;
                attributes.Put(PdfName.ListNumbering, TransformNumberingTypeToName(numberingType));
            }
            if (attributes.Size() > 1)
            {
                AccessibilityProperties properties = ((IAccessibleElement)renderer.GetModelElement()).GetAccessibilityProperties
                                                         ();
                RemoveSameAttributesTypeIfPresent(properties, attributesType);
                properties.AddAttributes(attributes);
            }
        }
Exemple #5
0
        public override void ProcessEnd(IElementNode element, ProcessorContext context)
        {
            base.ProcessEnd(element, context);
            IPropertyContainer elementResult = base.GetElementResult();

            if (elementResult is IAccessibleElement)
            {
                ((IAccessibleElement)elementResult).GetAccessibilityProperties().SetRole(StandardRoles.TH);
                if (context.GetPdfDocument() == null || context.GetPdfDocument().IsTagged())
                {
                    String scope = element.GetAttribute(AttributeConstants.SCOPE);
                    AccessibilityProperties properties = ((IAccessibleElement)elementResult).GetAccessibilityProperties();
                    PdfDictionary           attributes = new PdfDictionary();
                    attributes.Put(PdfName.O, PdfName.Table);
                    if (scope != null && (AttributeConstants.ROW.EqualsIgnoreCase(scope) || AttributeConstants.ROWGROUP.EqualsIgnoreCase
                                              (scope)))
                    {
                        attributes.Put(PdfName.Scope, PdfName.Row);
                        properties.AddAttributes(new PdfStructureAttributes(attributes));
                    }
                    else
                    {
                        if (scope != null && (AttributeConstants.COL.EqualsIgnoreCase(scope) || AttributeConstants.COLGROUP.EqualsIgnoreCase
                                                  (scope)))
                        {
                            attributes.Put(PdfName.Scope, PdfName.Column);
                            properties.AddAttributes(new PdfStructureAttributes(attributes));
                        }
                        else
                        {
                            ILog logger = LogManager.GetLogger(typeof(iText.Html2pdf.Attach.Impl.Tags.ThTagWorker));
                            logger.Warn(MessageFormatUtil.Format(iText.Html2pdf.LogMessageConstant.NOT_SUPPORTED_TH_SCOPE_TYPE, scope)
                                        );
                        }
                    }
                }
            }
        }