This guide explains how to create a program that uses DsPdf .NET to generate and save to disk a PDF file with the "Hello, World!" text.

Document Solutions for PDF .NET assemblies are built for .NET Standard 2.0, and can be used with any target that supports it. In this short tutorial, we show how to build a .NET console application. The tutorial takes you through the steps required to do that in Visual Studio on Windows, or Visual Studio Code on macOS and Linux.

Create an empty console application

Using Visual Studio on Windows

  1. Open Visual Studio for Windows.
  2. Create a new Console App.
  3. Right click the project in Solution Explorer and choose Manage NuGet Packages.
  4. Select nuget.org as the Package source.
  5. Click the Browse tab and enter "DS.Documents" as the search string. You should see several DS.Documents packages listed.
  6. Select DS.Documents.Pdf, and click Install. Accept the license agreement.

This will add the required references to your application. You can now jump to Adding Code topic below to modify the application so that it generates the PDF.

Using Visual Studio Code on macOS and Linux

  1. In a terminal window (you may use the Terminal in Visual Studio Code), type the following commands:
$ mkdir ~/MyApp # create a directory for the application$ cd ~/MyApp$ dotnet new console # create a .NET console application with MyApp.csproj and Program.cs files$ dotnet add package DS.Documents.Pdf # add a reference to the package and fetch it
  1. Open the project in Visual Studio Code. Your MyApp.csproj now looks like this:
<Project Sdk="Microsoft.NET.Sdk">    <PropertyGroup>        <OutputType>Exe</OutputType>        <TargetFramework>net8.0</TargetFramework>    </PropertyGroup>    <ItemGroup>        <PackageReference Include="DS.Documents.Pdf" Version="9.2.2" />    </ItemGroup></Project>
  1. In a terminal window, type the following command to build and run the app:
$ cd ~/MyApp$ dotnet run # runs the default app

At this point you should see the "Hello, World!" printed in the terminal window (the default behavior of a new console app). Now modify the application so that it generates the PDF instead.

Add Code

Open Program.cs in Visual Studio or Visual Studio Code, and modify it so that it looks like this:
using System;using System.Drawing;using GrapeCity.Documents.Pdf;using GrapeCity.Documents.Text;
namespace MyApp{ class Program { static void Main(string[] args) { // Create a new PDF document: GcPdfDocument doc = new GcPdfDocument(); // Add a page, get its graphics: GcPdfGraphics g = doc.NewPage().Graphics; // Render a string into the page: g.DrawString("Hello, World!", // Use a standard font (the 14 standard PDF fonts are built into DsPdf .NET // and are always available): new TextFormat() { Font = StandardFonts.Times, FontSize = 12 }, // DsPdf .NET page coordinates start at top left corner, using 72 dpi by default: new PointF(72, 72)); // Save the PDF: doc.Save("HelloWorld.pdf"); } }}
Now run the application:
$ cd ~/MyApp$ dotnet run # runs MyApp

That's all it takes to generate a PDF file using DsPdf .NET. The HelloWorld.pdf should now appear in your project directory.

Essentially the same program is implemented by the Hello, World! sample, so you can see it in action:

This concludes this short guide. For more information please see the About page and the Docs.