From 23992c1c4a8c9dff0b1b5a2def912a1ad7a60171 Mon Sep 17 00:00:00 2001 From: Claudia Murialdo Date: Mon, 25 Sep 2023 18:28:41 -0300 Subject: [PATCH] Cherry pick branch 'genexuslabs:itext8' into beta --- .../GxPdfReportsCS/PDFReportItext8.cs | 60 ++++++++----------- 1 file changed, 24 insertions(+), 36 deletions(-) diff --git a/dotnet/src/dotnetcore/GxPdfReportsCS/PDFReportItext8.cs b/dotnet/src/dotnetcore/GxPdfReportsCS/PDFReportItext8.cs index 16bc9d5b8..e9ec7b89f 100644 --- a/dotnet/src/dotnetcore/GxPdfReportsCS/PDFReportItext8.cs +++ b/dotnet/src/dotnetcore/GxPdfReportsCS/PDFReportItext8.cs @@ -103,6 +103,7 @@ protected override void init(ref int gxYPage, ref int gxXPage, int pageWidth, in pdfDocument = new PdfDocument(writer); pdfDocument.SetDefaultPageSize(this.pageSize); document = new Document(pdfDocument); + document.SetFontProvider(new DefaultFontProvider()); } catch (PdfException de) @@ -775,7 +776,7 @@ public override void GxDrawText(String sTxt, int left, int top, int right, int b try { ConverterProperties converterProperties = new ConverterProperties(); - FontProvider fontProvider = new DefaultFontProvider(); + FontProvider fontProvider = document.GetFontProvider(); if (IsTrueType(baseFont)) { Hashtable locations = GetFontLocations(); @@ -794,7 +795,6 @@ public override void GxDrawText(String sTxt, int left, int top, int right, int b } } } - document.SetFontProvider(fontProvider); converterProperties.SetFontProvider(fontProvider); bottomAux = (float)convertScale(bottom); topAux = (float)convertScale(top); @@ -960,12 +960,13 @@ public override void GxDrawText(String sTxt, int left, int top, int right, int b private void ProcessHTMLElement(Rectangle htmlRectangle, YPosition currentYPosition, IBlockElement blockElement) { Div div = blockElement as Div; - if (div != null) { + if (div != null) + { // Iterate through the children of the Div and process each child element recursively foreach (IElement child in div.GetChildren()) if (child is IBlockElement) ProcessHTMLElement(htmlRectangle, currentYPosition, (IBlockElement)child); - + } float blockElementHeight = GetBlockElementHeight(blockElement, htmlRectangle); @@ -976,55 +977,42 @@ private void ProcessHTMLElement(Rectangle htmlRectangle, YPosition currentYPosit return; } + Paragraph p = blockElement as Paragraph; + Table table = blockElement as Table; + List list = blockElement as List; Link anchor = blockElement as Link; - if (anchor != null) + Image image = blockElement as Image; + if (p != null) { - anchor.SetFixedPosition(this.getPage(), htmlRectangle.GetX(), currentYPosition.CurrentYPosition - blockElementHeight, htmlRectangle.GetWidth()); - document.Add((IBlockElement) anchor); - currentYPosition.CurrentYPosition = currentYPosition.CurrentYPosition - blockElementHeight; - return; + p.SetFixedPosition(this.getPage(), htmlRectangle.GetX(), currentYPosition.CurrentYPosition - blockElementHeight, htmlRectangle.GetWidth()); + document.Add(p); } - - List list = blockElement as List; - if (list != null) + else if (table != null) + { + table.SetFixedPosition(this.getPage(), htmlRectangle.GetX(), currentYPosition.CurrentYPosition - blockElementHeight, htmlRectangle.GetWidth()); + document.Add(table); + } + else if (list != null) { // This is a hack for the specific case of rendering a list as cb.Add(list) fails to add numeration to each element but document.Add(list) fails to // consider the numeration of each element as part of it. Solution is to use document.Add(list) and move the list to the right. float numWidth = new Paragraph("1. ").CreateRendererSubTree().SetParent(document.GetRenderer()).Layout(new LayoutContext(new LayoutArea(this.getPage(), htmlRectangle))).GetOccupiedArea().GetBBox().GetHeight(); list.SetFixedPosition(this.getPage(), htmlRectangle.GetX() + numWidth, currentYPosition.CurrentYPosition - blockElementHeight, htmlRectangle.GetWidth()); - document.Add(list); - currentYPosition.CurrentYPosition = currentYPosition.CurrentYPosition - blockElementHeight; - return; } - - Table table = blockElement as Table; - if (table != null) - { - table.SetFixedPosition(this.getPage(), htmlRectangle.GetX(), currentYPosition.CurrentYPosition - blockElementHeight, htmlRectangle.GetWidth()); - document.Add(table); - currentYPosition.CurrentYPosition = currentYPosition.CurrentYPosition - blockElementHeight; - return; - } - - Paragraph p = blockElement as Paragraph; - if (p != null) + else if (anchor != null) { - p.SetFixedPosition(this.getPage(), htmlRectangle.GetX(), currentYPosition.CurrentYPosition - blockElementHeight, htmlRectangle.GetWidth()); - document.Add(p); - currentYPosition.CurrentYPosition = currentYPosition.CurrentYPosition - blockElementHeight; - return; + anchor.SetFixedPosition(this.getPage(), htmlRectangle.GetX(), currentYPosition.CurrentYPosition - blockElementHeight, htmlRectangle.GetWidth()); + document.Add((IBlockElement)anchor); } - - Image image = blockElement as Image; - if (image != null) + else if (image != null) { image.SetFixedPosition(this.getPage(), htmlRectangle.GetX(), currentYPosition.CurrentYPosition - blockElementHeight, htmlRectangle.GetWidth()); document.Add(image); - currentYPosition.CurrentYPosition = currentYPosition.CurrentYPosition - blockElementHeight; - return; } + currentYPosition.CurrentYPosition = currentYPosition.CurrentYPosition - blockElementHeight; + return; } private float GetBlockElementHeight(IBlockElement blockElement, Rectangle htmlRectangle)