protected void DrawText(XGraphics gfx, PdfPage page) { int rectHeight = 200; int middleRectY = 300; int topRectY = 230; int topRectHeight = 300; XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode); XFont font = new XFont(FontName, BaseFontSize, XFontStyle.Regular, options); XStringFormat format = new XStringFormat(); XRect topRect = new XRect(LeftIndent, topRectY, TextWidth, topRectHeight); gfx.DrawRectangle(XBrushes.White, topRect); format.Alignment = XStringAlignment.Far; gfx.DrawString($"{_decision.Name} від {_decision.Date:dd/MM/yyyy}", font, XBrushes.Black, topRect, format); font = new XFont(FontName, TextFontSize, XFontStyle.Regular, options); TextFormatter tfx = new TextFormatter(gfx); XRect middleRect = new XRect(LeftIndent, middleRectY, TextWidth, rectHeight); tfx.PrepareDrawString(_decision.Description, font, new XRect(LeftIndent, middleRectY, TextWidth, double.MaxValue), out var lastCharIndex, out var neededHeight); if (neededHeight > rectHeight) { middleRect = new XRect(LeftIndent, middleRectY, TextWidth, neededHeight); } if (neededHeight > page.Height - rectHeight - middleRect.Y) { middleRect = new XRect(LeftIndent, middleRectY, TextWidth, page.Height - middleRect.Y - 30); tfx.PrepareDrawString(_decision.Description, font, middleRect, out lastCharIndex, out neededHeight); middleRect = new XRect(LeftIndent, middleRectY, TextWidth, neededHeight); } tfx.DrawString(_decision.Description, font, XBrushes.Black, middleRect, XStringFormats.TopLeft); if (lastCharIndex == -1) { if (page.Height < neededHeight + middleRectY + BottomRectHeightWithStock) { PdfPage newPage = document.AddPage(); gfx = XGraphics.FromPdfPage(newPage); middleRect = new XRect(LeftIndent, 0, TextWidth, 0); } DrawBottom(gfx, format, middleRect, font); } else { DrawNextPage(_decision.Description.Substring(lastCharIndex + 1), font); } }
protected void DrawText(XGraphics gfx, PdfPage page) { const int rectHeight = 200; const int middleRectY = 300; const int topRectY = 230; const int topRectHeight = 300; var options = new XPdfFontOptions(PdfFontEncoding.Unicode); var font = new XFont(FontName, BaseFontSize, XFontStyle.Regular, options); var format = new XStringFormat(); var topRect = new XRect(LeftIndent, topRectY, TextWidth, topRectHeight); gfx.DrawRectangle(XBrushes.White, topRect); format.Alignment = XStringAlignment.Far; gfx.DrawString($"{_methodicDocument.Name} від {_methodicDocument.Date:dd/MM/yyyy}", font, XBrushes.Black, topRect, format); font = new XFont(FontName, TextFontSize, XFontStyle.Regular, options); var tfx = new TextFormatter(gfx); var middleRect = new XRect(LeftIndent, middleRectY, TextWidth, rectHeight); var documentTypeFont = new XFont(FontName, BaseFontSize + 4, XFontStyle.Bold, options); gfx.DrawString($"{MethodicDocumentTypeParser(_methodicDocument.Type)}", documentTypeFont, XBrushes.Black, 295, 200, XStringFormats.BaseLineCenter); tfx.PrepareDrawString(_methodicDocument.Description, font, new XRect(LeftIndent, middleRectY, TextWidth, double.MaxValue), out var lastCharIndex, out var neededHeight); if (neededHeight > rectHeight) { middleRect = new XRect(LeftIndent, middleRectY, TextWidth, neededHeight); } if (neededHeight > page.Height - rectHeight - middleRect.Y) { middleRect = new XRect(LeftIndent, middleRectY, TextWidth, page.Height - middleRect.Y - 30); tfx.PrepareDrawString(_methodicDocument.Description, font, middleRect, out lastCharIndex, out neededHeight); middleRect = new XRect(LeftIndent, middleRectY, TextWidth, neededHeight); } tfx.DrawString(_methodicDocument.Description, font, XBrushes.Black, middleRect, XStringFormats.TopLeft); if (lastCharIndex != -1) { DrawNextPage(_methodicDocument.Description[(lastCharIndex + 1)..], font);
void DrawNextPage(string text, XFont font) { int middleRectY = 40; PdfPage page = document.AddPage(); XGraphics gfx = XGraphics.FromPdfPage(page); XStringFormat format = new XStringFormat(); TextFormatter tfx = new TextFormatter(gfx); XRect middleRect = new XRect(LeftIndent, middleRectY, TextWidth, double.MaxValue); tfx.PrepareDrawString(text, font, middleRect, out var newIndexOfLastCharOnPage, out var newNeededHeight); if (newNeededHeight > page.Height - BottomRectHeight) { middleRect = new XRect(LeftIndent, middleRectY, TextWidth, page.Height - BottomRectHeight); tfx.PrepareDrawString(text, font, middleRect, out newIndexOfLastCharOnPage, out newNeededHeight); } middleRect = new XRect(LeftIndent, middleRectY, TextWidth, newNeededHeight); tfx.DrawString(text, font, XBrushes.Black, middleRect, format); if (newIndexOfLastCharOnPage == -1) { if (page.Height < newNeededHeight + middleRectY + BottomRectHeightWithStock) { PdfPage newPage = document.AddPage(); gfx = XGraphics.FromPdfPage(newPage); middleRect = new XRect(LeftIndent, 0, TextWidth, 0); } DrawBottom(gfx, format, middleRect, font); } else { DrawNextPage(text.Substring(newIndexOfLastCharOnPage + 1), font); } }