|
3 | 3 | using System.Collections.Generic; |
4 | 4 | using System.Globalization; |
5 | 5 | using System.IO; |
| 6 | +using System.Linq; |
6 | 7 | using System.Text; |
7 | 8 | using GeneXus; |
8 | 9 | using iText.Barcodes; |
@@ -805,14 +806,27 @@ public override void GxDrawText(String sTxt, int left, int top, int right, int b |
805 | 806 | Rectangle htmlRectangle = new Rectangle(llx, lly, urx - llx, ury - lly); |
806 | 807 | YPosition yPosition = new YPosition(htmlRectangle.GetTop()); |
807 | 808 |
|
808 | | - PdfCanvas htmlPdfCanvas = new PdfCanvas(pdfPage); |
809 | 809 | Canvas htmlCanvas = new Canvas(canvas, htmlRectangle); |
810 | | - |
| 810 | + htmlCanvas.SetFontProvider(fontProvider); |
811 | 811 |
|
812 | 812 | //Iterate over the elements (a.k.a the parsed HTML string) and handle each case accordingly |
813 | 813 | IList<IElement> elements = HtmlConverter.ConvertToElements(sTxt, converterProperties); |
814 | 814 | foreach (IElement element in elements) |
815 | | - ProcessHTMLElement(htmlRectangle, yPosition, (IBlockElement)element); |
| 815 | + { |
| 816 | + bool fitInPage = ProcessHTMLElement(htmlRectangle, yPosition, (IBlockElement)element, htmlCanvas, drawingPageHeight); |
| 817 | + if (!fitInPage) |
| 818 | + { |
| 819 | + GxEndPage(); |
| 820 | + GxStartPage(); |
| 821 | + htmlCanvas.Close(); |
| 822 | + float remainingDrawingPageHeight = bottomAux - drawingPageHeight; |
| 823 | + htmlRectangle.SetY(drawingPageHeight - (remainingDrawingPageHeight)); |
| 824 | + htmlCanvas = new Canvas(canvas, htmlRectangle); |
| 825 | + htmlCanvas.SetFontProvider(fontProvider); |
| 826 | + ProcessHTMLElement(htmlRectangle, yPosition, (IBlockElement)element, htmlCanvas, remainingDrawingPageHeight); |
| 827 | + } |
| 828 | + } |
| 829 | + |
816 | 830 | } |
817 | 831 | catch (Exception ex1) |
818 | 832 | { |
@@ -954,56 +968,24 @@ public override void GxDrawText(String sTxt, int left, int top, int right, int b |
954 | 968 | } |
955 | 969 | } |
956 | 970 |
|
957 | | - private void ProcessHTMLElement(Rectangle htmlRectangle, YPosition currentYPosition, IBlockElement blockElement) |
| 971 | + private bool ProcessHTMLElement(Rectangle htmlRectangle, YPosition currentYPosition, IBlockElement blockElement, Canvas canvas, float drawingPageHeight) |
958 | 972 | { |
959 | | - Div div = blockElement as Div; |
960 | | - if (div != null) |
961 | | - { |
962 | | - // Iterate through the children of the Div and process each child element recursively |
963 | | - foreach (IElement child in div.GetChildren()) |
964 | | - if (child is IBlockElement) |
965 | | - ProcessHTMLElement(htmlRectangle, currentYPosition, (IBlockElement)child); |
966 | | - |
967 | | - } |
968 | 973 |
|
969 | 974 | float blockElementHeight = GetBlockElementHeight(blockElement, htmlRectangle); |
970 | 975 | float availableSpace = currentYPosition.CurrentYPosition - htmlRectangle.GetBottom(); |
971 | | - if (blockElementHeight > availableSpace) |
972 | | - { |
973 | | - GXLogging.Error(log, "You are trying to render an element of height " + blockElementHeight + " in a space of height " + availableSpace); |
974 | | - return; |
975 | | - } |
976 | | - |
977 | | - if (blockElement is Paragraph p) |
| 976 | + if (PageHeightExceeded(blockElementHeight, availableSpace)) |
978 | 977 | { |
979 | | - p.SetFixedPosition(this.getPage(), htmlRectangle.GetX(), currentYPosition.CurrentYPosition - blockElementHeight, htmlRectangle.GetWidth()); |
980 | | - document.Add(p); |
981 | | - } |
982 | | - else if (blockElement is Table table) |
983 | | - { |
984 | | - table.SetFixedPosition(this.getPage(), htmlRectangle.GetX(), currentYPosition.CurrentYPosition - blockElementHeight, htmlRectangle.GetWidth()); |
985 | | - document.Add(table); |
986 | | - } |
987 | | - else if (blockElement is List list) |
988 | | - { |
989 | | - list.SetFixedPosition(this.getPage(), htmlRectangle.GetX(), currentYPosition.CurrentYPosition - blockElementHeight, htmlRectangle.GetWidth()); |
990 | | - document.Add(list); |
991 | | - } |
992 | | - else if (blockElement is Link anchor) |
993 | | - { |
994 | | - anchor.SetFixedPosition(this.getPage(), htmlRectangle.GetX(), currentYPosition.CurrentYPosition - blockElementHeight, htmlRectangle.GetWidth()); |
995 | | - document.Add((IBlockElement)anchor); |
996 | | - } |
997 | | - else if (blockElement is Image image) |
998 | | - { |
999 | | - image.SetFixedPosition(this.getPage(), htmlRectangle.GetX(), currentYPosition.CurrentYPosition - blockElementHeight, htmlRectangle.GetWidth()); |
1000 | | - document.Add(image); |
| 978 | + GXLogging.Warn(log, "You are trying to render an element of height " + blockElementHeight + " in a space of height " + availableSpace); |
| 979 | + return false; |
1001 | 980 | } |
| 981 | + canvas.Add(blockElement); |
1002 | 982 | currentYPosition.CurrentYPosition = currentYPosition.CurrentYPosition - blockElementHeight; |
1003 | | - |
1004 | | - return; |
| 983 | + return true; |
| 984 | + } |
| 985 | + bool PageHeightExceeded(float bottomAux, float drawingPageHeight) |
| 986 | + { |
| 987 | + return bottomAux > drawingPageHeight; |
1005 | 988 | } |
1006 | | - |
1007 | 989 | private float GetBlockElementHeight(IBlockElement blockElement, Rectangle htmlRectangle) |
1008 | 990 | { |
1009 | 991 | return blockElement.CreateRendererSubTree().SetParent(document.GetRenderer()).Layout(new LayoutContext(new LayoutArea(this.getPage(), htmlRectangle))).GetOccupiedArea().GetBBox().GetHeight(); |
|
0 commit comments