public static readonly SizeF pageSize = PdfPageSize.A4; public static readonly float MarginLeft = CmInPixel(2.3); public static readonly float MarginRight = CmInPixel(2); public static readonly float MarginTop = CmInPixel(4.5); public static readonly float MarginBottom = CmInPixel(3.3); public static float CanvasWidth => pageSize.Width - MarginLeft - MarginRight; public static float CanvasHeigth => pageSize.Height - MarginTop - MarginBottom; public static float CmInPixel(double cm) { return (float)(cm / 2.54f * 72f); } public static double PixelInCm(float pixel) { return pixel / 72f * 2.54f; } public async void TestPDF() { PdfDocument document = new(); PdfPageSettings pagesettings = new() { Size = pageSize }; pagesettings.SetMargins(0, 0, 0, 0); document.PageSettings = pagesettings; var initialpage = document.Pages.Add(); PdfLayoutResult layoutResult = new(initialpage, new(0, 0, 0, 0)); PdfGrid grid = new(); grid.Columns.Add(2); for (int i = 1; i <= 37; i++) { PdfGridRow row = grid.Rows.Add(); row.Cells[0].Value = (i.ToString()); } grid.AllowRowBreakAcrossPages = true; RectangleF bounds = new() { X = MarginLeft, Y = Math.Max(layoutResult.Bounds.Bottom, MarginTop), Width = CanvasWidth, Height = CanvasHeigth - Math.Max(layoutResult.Bounds.Bottom, MarginTop) + MarginTop }; PdfLayoutFormat layoutFormat = new() { Break = PdfLayoutBreakType.FitPage, Layout = PdfLayoutType.Paginate, PaginateBounds = new() { X = MarginLeft, Y = MarginTop, Width = CanvasWidth, Height = CanvasHeigth }, }; layoutResult = grid.Draw(layoutResult.Page, bounds, layoutFormat); layoutResult.Page.Graphics.DrawRectangle(PdfPens.Red, layoutResult.Bounds); Debug.WriteLine($"Grid Height: {grid.Rows.Count * grid.Rows[0].Height}"); Debug.WriteLine($"LayoutResult Bounds: {layoutResult.Bounds.Height}"); MemoryStream documentStream = new(); document.Save(documentStream); await js.OpenInNewTab(documentStream.ToArray()); }