Create PDF with text

Generate PDF
11/2/2011

The following basic code sample demonstrates how to create new a new PDF document and draw text on it.

C# code sample

1 // Create a new PDF document with a single page 2 Document document = new Document(); 3 Page page = new Page(PageSize.A4); 4 document.Pages.Add(page); 5 6 // Create a text shape to draw text 7 TextShape textShape = new TextShape(50, 750, "Hello World!", Font.HelveticaBold, 16); 8 9 // Add the text to the page 10 page.Overlay.Add(textShape); 11 12 // write the target document to disk 13 // note that when the target document is written, the source streams 14 // must still be open. for efficiency reasons, all source page content 15 // is extracted as late as possible 16 using (FileStream file = new FileStream(@"..\..\HelloWorld.pdf", FileMode.Create, FileAccess.Write)) 17 { 18 document.Write(file); 19 }

VB.NET code sample

1 ' Create a new PDF document with a single page 2 Dim document As New Document() 3 Dim page As New Page(PageSize.A4) 4 document.Pages.Add(page) 5 6 ' Create a text shape to draw text 7 Dim textShape As New TextShape(50, 750, "Hello World!", Font.HelveticaBold, 16) 8 9 ' Add the text to the page 10 page.Overlay.Add(textShape) 11 12 ' write the target document to disk 13 ' note that when the target document is written, the source streams 14 ' must still be open. for efficiency reasons, all source page content 15 ' is extracted as late as possible 16 Using file As New FileStream("..\..\HelloWorld.pdf", FileMode.Create, FileAccess.Write) 17 document.Write(file) 18 End Using

Here is the result:

create pdf with text in c sharp (1).png