public DrawString ( string s, XFont font, XBrush brush, PointF point ) : void | ||
s | string | |
font | XFont | |
brush | XBrush | |
point | PointF | |
return | void |
// Create PDF document PdfDocument document = new PdfDocument(); // Add a page to the document PdfPage page = document.AddPage(); // Get XGraphics object from the page XGraphics gfx = XGraphics.FromPdfPage(page); // Draw the text on the page gfx.DrawString("Hello world!", new XFont("Arial", 12), XBrushes.Black, new XRect(50, 50, page.Width - 100, page.Height - 100), XStringFormats.Center); // Save the document document.Save("output.pdf");
// Create PDF document PdfDocument document = new PdfDocument(); // Add a page to the document PdfPage page = document.AddPage(); // Get XGraphics object from the page XGraphics gfx = XGraphics.FromPdfPage(page); // Define font and string format XFont font = new XFont("Verdana", 20, XFontStyle.Bold); XStringFormat format = new XStringFormat(); format.Alignment = XStringAlignment.Center; format.LineAlignment = XLineAlignment.Center; // Draw the text on the page gfx.DrawString("Hello", font, XBrushes.Blue, new XRect(50, 50, page.Width - 100, page.Height - 100), format); // Move to the next line gfx.DrawString("World!", font, XBrushes.Red, new XRect(50, 80, page.Width - 100, page.Height - 100), format); // Save the document document.Save("output.pdf");In this example, we create a PDF document, add a page to it, get an XGraphics object for the page, define a font and string format, and use DrawString method to draw two lines of text ("Hello" and "World!") on the page with different colors. We also use the string format to center the text horizontally and vertically on the page. PdfSharp is the package/library used here.
public DrawString ( string s, XFont font, XBrush brush, PointF point ) : void | ||
s | string | |
font | XFont | |
brush | XBrush | |
point | PointF | |
return | void |