Example of Hello World using C# language

Contents
[ ]

A “Hello World” example is traditionally used to introduce features of a programming language or software with a simple use case.

Aspose.PDF for .NET is a feature rich PDF API that allows the developers to embed PDF document creation, manipulation & conversion capabilities in their .NET applications. It supports working with many popular file formats including PDF, XFA, TXT, HTML, PCL, XML, XPS, EPUB, TEX and image file formats. In this article, we are creating a PDF document containing text “Hello World!”. After installing Aspose.PDF for .NET in your environment, you can execute below code sample to see how Aspose.PDF API works.

The following code snippet also work with Aspose.PDF.Drawing library.

Below code snippet follows these steps:

  1. Instantiate a Document object.
  2. Add a Page to document object.
  3. Create a TextFragment object.
  4. Add TextFragment to Paragraph collection of the page.
  5. Save resultant PDF document.

Following code snippet is a Hello World program to exhibit working of Aspose.PDF for .NET API.


private static readonly string dataDir = "..\\..\\..\\Samples\\";
// Initialize document object
Document document = new Document();
// Add page
Page page = document.Pages.Add();
// Add text to new page
page.Paragraphs.Add(new Aspose.Pdf.Text.TextFragment("Hello World!"));
// Save updated PDF
var outputFileName = dataDir + "HelloWorld_out.pdf";
document.Save(outputFileName);