Home arrow Samples arrow Pages Sizes Make Text BiggerMake Text SmallerReset Text Size
Hello World Sample

This sample shows how to create a PDF document, add a page, draw some text, and save it to disk.

// Create a new PDF document
PdfDocument document = new PdfDocument();
 
// Create an empty page
PdfPage page = document.AddPage();
 
// Get an XGraphics object for drawing
XGraphics gfx = XGraphics.FromPdfPage(page);
 
// Create a font
XFont font = new XFont("Verdana", 20, XFontStyle.Bold);
 
// Draw the text
gfx.DrawString("Hello, World!", font, XBrushes.Black,
  new XRect(0, 0, page.Width, page.Height),
  XStringFormat.Center);
 
// Save the document...
string filename = "HelloWorld.pdf";
document.Save(filename);
// ...and start a viewer.
Process.Start(filename);

See the PDF file created by this sample: HelloWorld.pdf (5 kB)

And here is how it looks like (click image to enlarge):

Hello, World!
Hello, World!

 
< Prev   Next >
New! We no longer maintain this site. Visit the new PDFsharp and MigraDoc Foundation Homepage. © 2009 empira Software GmbH | Impressum | Created with Joomla!