PDF HelloWorld in C#, VB.NET

  • Demo
  • C# source
  • VB.Net source

The sample demonstrates how to write a "HelloWorld" to a PDF document.

Download HelloWorld.pdf

using System.Drawing;
using Spire.Pdf;
using Spire.Pdf.Graphics;

namespace HelloWorld
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a pdf document.
            PdfDocument doc = new PdfDocument();

            // Create one page
            PdfPageBase page =doc.Pages.Add();

            //Draw the text
            page.Canvas.DrawString("Hello, World!",
                                   new PdfFont(PdfFontFamily.Helvetica, 30f),
                                   new PdfSolidBrush(Color.Black),
                                   10, 10);

            //Save pdf file.
            doc.SaveToFile("HelloWorld.pdf");
            doc.Close();

            //Launching the Pdf file.
            System.Diagnostics.Process.Start("HelloWorld.pdf");
        }
    }
}

Imports System.Drawing
Imports Spire.Pdf
Imports Spire.Pdf.Graphics

Namespace HelloWorld
    Friend Class Program
        Shared Sub Main(ByVal args() As String)
            'Create a pdf document.
            Dim doc As New PdfDocument()

            ' Create one page
            Dim page As PdfPageBase = doc.Pages.Add()

            'Draw the text
            page.Canvas.DrawString("Hello, World!", _
                   New PdfFont(PdfFontFamily.Helvetica, 30.0F), _
                   New PdfSolidBrush(Color.Black), 10, 10)

            'Save pdf file.
            doc.SaveToFile("HelloWorld.pdf")
            doc.Close()

            'Launching the Pdf file.
            Process.Start("HelloWorld.pdf")
        End Sub
    End Class
End Namespace