Created
October 19, 2024 08:16
-
-
Save documentprocessing/5cc9bad8cb899f4f971368555ae3970b to your computer and use it in GitHub Desktop.
Insert Table in a PDF document using PDFSharp for .NET
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using PdfSharp.Pdf; | |
| using PdfSharp.Drawing; | |
| PdfDocument document = new PdfDocument(); | |
| PdfPage page = document.AddPage(); | |
| XGraphics gfx = XGraphics.FromPdfPage(page); | |
| XFont font = new XFont("Verdana", 12, XFontStyle.Regular); | |
| int rows = 5; | |
| int cols = 3; | |
| double cellWidth = 100; | |
| double cellHeight = 30; | |
| for (int i = 0; i < rows; i++) | |
| { | |
| for (int j = 0; j < cols; j++) | |
| { | |
| double x = j * cellWidth; | |
| double y = i * cellHeight; | |
| gfx.DrawRectangle(XPens.Black, x, y, cellWidth, cellHeight); | |
| gfx.DrawString($"Cell {i + 1},{j + 1}", font, XBrushes.Black, | |
| new XRect(x, y, cellWidth, cellHeight), XStringFormats.Center); | |
| } | |
| } | |
| document.Save("TableInPDF.pdf"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment