//Create a new document
PdfDocument doc = new PdfDocument();
//Add a page
PdfPage page = doc.Pages.Add();
//Create Pdf graphics for the page
PdfGraphics g = page.Graphics;
//Create a solid brush
PdfBrush brush = new PdfSolidBrush(Color.Black);
//Set the font with bold
PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 10f, PdfFontStyle.Bold);
//Draw the rectangle with Gray color
g.DrawRectangle(new PdfPen(PdfBrushes.Gray, 1), PdfBrushes.White, new RectangleF(100, 200, 100, 50));
//Draw the text
g.DrawString("Hello world!", font, brush, new PointF(120, 220));
//Save and close the document
doc.Save("Sample.pdf");
doc.Close(true); |