using PdfSharp.Drawing; // Create a new PDF document PdfDocument document = new PdfDocument(); PdfPage page = document.AddPage(); // Get the XGraphics object for the page XGraphics gfx = XGraphics.FromPdfPage(page); // Draw a line on the PDF page gfx.DrawLine(XPens.Black, 10, 10, 100, 100); // Save the PDF document document.Save("example.pdf");
using PdfSharp.Drawing; using PdfSharp.Pdf; // Create a new PDF document PdfDocument document = new PdfDocument(); PdfPage page = document.AddPage(); // Get the XGraphics object for the page XGraphics gfx = XGraphics.FromPdfPage(page); // Create a font and brush for the text XFont font = new XFont("Arial", 12); XBrush brush = XBrushes.Black; // Draw the text on the PDF page gfx.DrawString("Hello, world!", font, brush, new XRect(10, 10, 100, 20), XStringFormats.TopLeft); // Save the PDF document document.Save("example.pdf");This example creates a new PDF document with a single page and adds the text "Hello, world!" to the page using the XGraphics.DrawString method. Package library: PdfSharp.Charting.