示例#1
0
        /* (non-Javadoc)
         * @see com.itextpdf.html2pdf.attach.impl.tags.DivTagWorker#processEnd(com.itextpdf.html2pdf.html.node.IElementNode, com.itextpdf.html2pdf.attach.ProcessorContext)
         */
        public override void ProcessEnd(IElementNode element, ProcessorContext context)
        {
            base.ProcessEnd(element, context);
            String url = element.GetAttribute(AttributeConstants.HREF);

            if (url != null)
            {
                String @base = context.GetBaseUri();
                if (@base != null)
                {
                    UriResolver uriResolver = new UriResolver(@base);
                    if (!(url.StartsWith("#") && uriResolver.IsLocalBaseUri()))
                    {
                        try {
                            String resolvedUri = uriResolver.ResolveAgainstBaseUri(url).ToExternalForm();
                            if (!url.EndsWith("/") && resolvedUri.EndsWith("/"))
                            {
                                resolvedUri = resolvedUri.JSubstring(0, resolvedUri.Length - 1);
                            }
                            if (!resolvedUri.StartsWith("file:"))
                            {
                                url = resolvedUri;
                            }
                        }
                        catch (UriFormatException) {
                        }
                    }
                }
                ((Div)GetElementResult()).GetAccessibilityProperties().SetRole(StandardRoles.LINK);
                LinkHelper.ApplyLinkAnnotation(GetElementResult(), url);
            }
            if (GetElementResult() != null)
            {
                String name = element.GetAttribute(AttributeConstants.NAME);
                GetElementResult().SetProperty(Property.DESTINATION, name);
            }
        }
示例#2
0
        /* (non-Javadoc)
         * @see com.itextpdf.html2pdf.attach.impl.tags.SpanTagWorker#processEnd(com.itextpdf.html2pdf.html.node.IElementNode, com.itextpdf.html2pdf.attach.ProcessorContext)
         */
        public override void ProcessEnd(IElementNode element, ProcessorContext context)
        {
            base.ProcessEnd(element, context);
            String url = element.GetAttribute(AttributeConstants.HREF);

            if (url != null)
            {
                String @base = context.GetBaseUri();
                if (@base != null)
                {
                    UriResolver uriResolver = new UriResolver(@base);
                    if (!(url.StartsWith("#") && uriResolver.IsLocalBaseUri()))
                    {
                        try {
                            String resolvedUri = uriResolver.ResolveAgainstBaseUri(url).ToExternalForm();
                            if (!url.EndsWith("/") && resolvedUri.EndsWith("/"))
                            {
                                resolvedUri = resolvedUri.JSubstring(0, resolvedUri.Length - 1);
                            }
                            if (!resolvedUri.StartsWith("file:"))
                            {
                                url = resolvedUri;
                            }
                        }
                        catch (UriFormatException) {
                        }
                    }
                }
                for (int i = 0; i < GetAllElements().Count; i++)
                {
                    if (GetAllElements()[i] is RunningElement)
                    {
                        continue;
                    }
                    if (GetAllElements()[i] is IBlockElement)
                    {
                        Div simulatedDiv = new Div();
                        simulatedDiv.GetAccessibilityProperties().SetRole(StandardRoles.LINK);
                        Transform cssTransform = GetAllElements()[i].GetProperty <Transform>(Property.TRANSFORM);
                        if (cssTransform != null)
                        {
                            GetAllElements()[i].DeleteOwnProperty(Property.TRANSFORM);
                            simulatedDiv.SetProperty(Property.TRANSFORM, cssTransform);
                        }
                        FloatPropertyValue?floatPropVal = GetAllElements()[i].GetProperty <FloatPropertyValue?>(Property.FLOAT);
                        if (floatPropVal != null)
                        {
                            GetAllElements()[i].DeleteOwnProperty(Property.FLOAT);
                            simulatedDiv.SetProperty(Property.FLOAT, floatPropVal);
                        }
                        simulatedDiv.Add((IBlockElement)GetAllElements()[i]);
                        String display = childrenDisplayMap.JRemove(GetAllElements()[i]);
                        if (display != null)
                        {
                            childrenDisplayMap.Put(simulatedDiv, display);
                        }
                        GetAllElements()[i] = simulatedDiv;
                    }
                    LinkHelper.ApplyLinkAnnotation(GetAllElements()[i], url);
                }
            }
            if (!GetAllElements().IsEmpty())
            {
                String             name         = element.GetAttribute(AttributeConstants.NAME);
                IPropertyContainer firstElement = GetAllElements()[0];
                firstElement.SetProperty(Property.DESTINATION, name);
            }
        }