public virtual void LangAttrInDivAndSpanForConvertToElementsMethodTest() { String html = sourceFolder + "langAttrInDivAndSpanForTagPdfTest.html"; IList <IElement> elemList = HtmlConverter.ConvertToElements(new FileStream(html, FileMode.Open, FileAccess.Read )); Div div = (Div)elemList[0]; NUnit.Framework.Assert.AreEqual("la", div.GetAccessibilityProperties().GetLanguage()); Paragraph p = (Paragraph)div.GetChildren()[0]; NUnit.Framework.Assert.IsNull(p.GetAccessibilityProperties().GetLanguage()); div = (Div)div.GetChildren()[1]; NUnit.Framework.Assert.AreEqual("en", div.GetAccessibilityProperties().GetLanguage()); div = (Div)elemList[1]; NUnit.Framework.Assert.AreEqual("ru", div.GetAccessibilityProperties().GetLanguage()); p = (Paragraph)div.GetChildren()[0]; NUnit.Framework.Assert.IsNull(p.GetAccessibilityProperties().GetLanguage()); div = (Div)div.GetChildren()[1]; NUnit.Framework.Assert.IsNull(div.GetAccessibilityProperties().GetLanguage()); p = (Paragraph)elemList[2]; Text text = (Text)p.GetChildren()[0]; NUnit.Framework.Assert.IsNull(text.GetAccessibilityProperties().GetLanguage()); text = (Text)p.GetChildren()[1]; NUnit.Framework.Assert.AreEqual("ru", text.GetAccessibilityProperties().GetLanguage()); text = (Text)p.GetChildren()[2]; NUnit.Framework.Assert.AreEqual("en", text.GetAccessibilityProperties().GetLanguage()); text = (Text)p.GetChildren()[3]; NUnit.Framework.Assert.AreEqual("ru", text.GetAccessibilityProperties().GetLanguage()); text = (Text)p.GetChildren()[4]; NUnit.Framework.Assert.IsNull(text.GetAccessibilityProperties().GetLanguage()); }
private void DrawSimulatedDiv(PdfPage page, IDictionary <int, Object> styles, float[] margins, bool drawBackground , int pageNumber, bool recalculateBodyAreaForContentSize) { Div pageBordersSimulation = new Div().SetFillAvailableArea(true); foreach (KeyValuePair <int, Object> entry in styles) { if ((entry.Key == Property.BACKGROUND || entry.Key == Property.BACKGROUND_IMAGE) && !drawBackground) { continue; } pageBordersSimulation.SetProperty(entry.Key, entry.Value); } pageBordersSimulation.GetAccessibilityProperties().SetRole(StandardRoles.ARTIFACT); Rectangle backgroundArea = new Rectangle(page.GetTrimBox()).ApplyMargins(margins[0], margins[1], margins[2 ], margins[3], false); if (recalculateBodyAreaForContentSize) { if (pageStylesPropertiesMap.Get(pageNumber).lowestAndHighest == null) { return; } HtmlBodyStylesApplierHandler.LowestAndHighest lowestAndHighest = pageStylesPropertiesMap.Get(pageNumber).lowestAndHighest; RecalculateBackgroundAreaForBody(backgroundArea, pageBordersSimulation, lowestAndHighest); } if (pdfCanvas == null) { pdfCanvas = new PdfCanvas(page.NewContentStreamBefore(), page.GetResources(), page.GetDocument()); } iText.Layout.Canvas canvas = new iText.Layout.Canvas(pdfCanvas, backgroundArea); canvas.EnableAutoTagging(page); canvas.Add(pageBordersSimulation); canvas.Close(); }
public override IPropertyContainer GetElementResult() { Div div = (Div)base.GetElementResult(); div.GetAccessibilityProperties().SetRole("H" + i); return(base.GetElementResult()); }
/// <summary>Convenience method to write a text aligned about the specified point</summary> /// <param name="p"> /// paragraph of text to be placed to the page. By default it has no leading and is written in single line. /// Set width to write multiline text. /// </param> /// <param name="x">the point about which the text will be aligned and rotated</param> /// <param name="y">the point about which the text will be aligned and rotated</param> /// <param name="pageNumber">the page number to write the text</param> /// <param name="textAlign">horizontal alignment about the specified point</param> /// <param name="vertAlign">vertical alignment about the specified point</param> /// <param name="radAngle">the angle of rotation applied to the text, in radians</param> /// <returns>this object</returns> public virtual T ShowTextAligned(Paragraph p, float x, float y, int pageNumber, TextAlignment?textAlign, VerticalAlignment?vertAlign, float radAngle) { Div div = new Div(); div.SetTextAlignment(textAlign).SetVerticalAlignment(vertAlign); if (radAngle != 0) { div.SetRotationAngle(radAngle); } div.SetProperty(Property.ROTATION_POINT_X, x); div.SetProperty(Property.ROTATION_POINT_Y, y); float divSize = 5e3f; float divX = x; float divY = y; if (textAlign == TextAlignment.CENTER) { divX = x - divSize / 2; p.SetHorizontalAlignment(HorizontalAlignment.CENTER); } else { if (textAlign == TextAlignment.RIGHT) { divX = x - divSize; p.SetHorizontalAlignment(HorizontalAlignment.RIGHT); } } if (vertAlign == VerticalAlignment.MIDDLE) { divY = y - divSize / 2; } else { if (vertAlign == VerticalAlignment.TOP) { divY = y - divSize; } } if (pageNumber == 0) { pageNumber = 1; } div.SetFixedPosition(pageNumber, divX, divY, divSize).SetMinHeight(divSize); if (p.GetProperty <Leading>(Property.LEADING) == null) { p.SetMultipliedLeading(1); } div.Add(p.SetMargins(0, 0, 0, 0)); div.GetAccessibilityProperties().SetRole(StandardRoles.ARTIFACT); this.Add(div); return((T)(Object)this); }
/// <summary>Creates the page simulation elements.</summary> /// <param name="styles"> /// a /// <see cref="System.Collections.IDictionary{K, V}"/> /// containing the styles /// </param> /// <param name="context">the processor context</param> private void CreatePageSimulationElements(IDictionary <String, String> styles, ProcessorContext context) { pageBackgroundSimulation = new Div().SetFillAvailableArea(true); BackgroundApplierUtil.ApplyBackground(styles, context, pageBackgroundSimulation); pageBackgroundSimulation.GetAccessibilityProperties().SetRole(StandardRoles.ARTIFACT); pageBordersSimulation = new Div().SetFillAvailableArea(true); pageBordersSimulation.SetMargins(margins[0], margins[1], margins[2], margins[3]); pageBordersSimulation.SetBorderTop(borders[0]); pageBordersSimulation.SetBorderRight(borders[1]); pageBordersSimulation.SetBorderBottom(borders[2]); pageBordersSimulation.SetBorderLeft(borders[3]); pageBordersSimulation.GetAccessibilityProperties().SetRole(StandardRoles.ARTIFACT); }
public virtual void LangAttrInHtmlWithLangBodyWithLangForConvertToElementsMethodTest() { String html = sourceFolder + "langAttrInHtmlWithLangBodyWithLangTest.html"; IList <IElement> elemList = HtmlConverter.ConvertToElements(new FileStream(html, FileMode.Open, FileAccess.Read )); Paragraph p = (Paragraph)elemList[0]; NUnit.Framework.Assert.AreEqual("by", p.GetAccessibilityProperties().GetLanguage()); p = (Paragraph)elemList[1]; NUnit.Framework.Assert.AreEqual("en", p.GetAccessibilityProperties().GetLanguage()); Div div = (Div)elemList[2]; NUnit.Framework.Assert.AreEqual("by", div.GetAccessibilityProperties().GetLanguage()); p = (Paragraph)elemList[3]; NUnit.Framework.Assert.AreEqual("by", p.GetAccessibilityProperties().GetLanguage()); }
private void DrawSimulatedDiv(PdfPage page, IDictionary<int, Object> styles, float[] margins, bool drawBackground ) { Div pageBordersSimulation; pageBordersSimulation = new Div().SetFillAvailableArea(true); foreach (KeyValuePair<int, Object> entry in styles) { if ((entry.Key == Property.BACKGROUND || entry.Key == Property.BACKGROUND_IMAGE) && !drawBackground) { continue; } pageBordersSimulation.SetProperty(entry.Key, entry.Value); } pageBordersSimulation.GetAccessibilityProperties().SetRole(StandardRoles.ARTIFACT); iText.Layout.Canvas canvas = new Canvas(new PdfCanvas(page), page.GetDocument(), page.GetTrimBox().ApplyMargins (margins[0], margins[1], margins[2], margins[3], false)); canvas.EnableAutoTagging(page); canvas.Add(pageBordersSimulation); canvas.Close(); }
/// <summary>Creates the page simulation elements.</summary> /// <param name="styles"> /// a /// <see cref="System.Collections.IDictionary{K, V}"/> /// containing the styles /// </param> /// <param name="context">the processor context</param> private void CreatePageSimulationElements(IDictionary <String, String> styles, ProcessorContext context) { pageBackgroundSimulation = new Div().SetFillAvailableArea(true); BackgroundApplierUtil.ApplyBackground(styles, context, pageBackgroundSimulation); pageBackgroundSimulation.GetAccessibilityProperties().SetRole(StandardRoles.ARTIFACT); if (!pageBackgroundSimulation.HasOwnProperty(Property.BACKGROUND) && !pageBackgroundSimulation.HasOwnProperty (Property.BACKGROUND_IMAGE)) { pageBackgroundSimulation = null; } if (borders[0] == null && borders[1] == null && borders[2] == null && borders[3] == null) { pageBordersSimulation = null; return; } pageBordersSimulation = new Div().SetFillAvailableArea(true); pageBordersSimulation.SetMargins(margins[0], margins[1], margins[2], margins[3]); pageBordersSimulation.SetBorderTop(borders[0]); pageBordersSimulation.SetBorderRight(borders[1]); pageBordersSimulation.SetBorderBottom(borders[2]); pageBordersSimulation.SetBorderLeft(borders[3]); pageBordersSimulation.GetAccessibilityProperties().SetRole(StandardRoles.ARTIFACT); }
/* (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); } }