Urgent.News

What's breaking now, across hundreds of outlets.

Tech

Create, Fill, Encrypt and Sign PDFs in .NET With One Free NuGet Package

Sooner or later, most business apps need PDFs. Reports and invoices have to be generated, forms filled from your data, files protected with a password, archived in a long term format, or signed before they go out. sgcPDF .NET covers all of those jobs in one NuGet package. Everything happens in code, headless, with nothing to open on screen, so the same calls work in a console app or in a…

Creating, populating, securing, and digitally signing PDF documents in .NET is made simple with the sgcPDF .NET library, available as a free NuGet package. This versatile package handles various PDF-related tasks without requiring any visual interface, making it suitable for use in console applications or background services. The tutorial explores each task individually: generating a document with text, tables, and images; filling out forms; extracting content; encrypting using AES-256; saving as PDF/A-2b; and signing with PAdES B-B.

All the provided samples were compiled and executed successfully, yielding outputs that align with the expected results.

To begin, create a new console application and install the required packages: esegece.sgcPDF.Community and esegece.sgcPDF.sgcSign.Community. The latter package includes the signing key provider. These packages are compatible with various .NET versions, including netstandard2.0, net472, net6.0, net8.0, net9.0, and net10.0, ensuring broad compatibility with .NET Framework 4.6.2 and later, Mono, and Xamarin.

The samples are organized into separate files, each containing a static class with a Run() method. This structure allows the samples to be dropped into the project and executed using a single command. All functionality resides within the esegece.sgcPDF namespace, with the signing key package contributing to the esegece.sgcSign namespace.

The tutorial begins with creating a PDF that contains text, a table, and an image. The process starts by initializing a TsgcPDFDocument instance and adding a page to it. The document's title and author are set using the Info property. A page is then created with dimensions of 595 by 842 points (1/72 inch), with the origin positioned at the bottom left.

A title and a paragraph are drawn on the page, followed by a line separating the title from the subsequent content. The text "Sales grew in every region this quarter, led by the North office." is displayed using a Helvetica font with a size of 12 points.

Next, a table is introduced, consisting of three columns with corresponding headers: "Region," "Units," and "Revenue." Data is added to the table, including the regions North, South, East, and West, along with their respective units sold and revenue figures. The table's header font is set to HelveticaBold with a size of 11 points, while the default font for the table cells is set to Helvetica with a size of 11 points.

A light gray header background color is applied to distinguish the header row from the rest of the table. The image filename "logo.png" is drawn on the page, positioned 50 points from the left and 435 points from the top, with dimensions of 180 by 120 points. Finally, the PDF is saved as "01_create.pdf" using the SaveToFile method, and the number of pages in the document is displayed on the console.

Rewritten by urgent.news; may contain errors — check the original.

Source: dev.to

Read the original at dev.to →

Report a problem with this story

More in Tech

The hardest tarball

  • "Hard tarball" created with three files: file, empty file, hard link
  • Hard link renamed to "café" triggers UTF-8 pax header creation
  • Extraction results vary by system, 512 bytes stored differently

More from Tuesday, 10 November 2026 →