1. Products
  2.   Editor
  3.   .NET
  4.   PDFSharp
 
  

Open Source .NET SDK for working with PDF files

Free & Powerful Open Source .NET API to create, edit and merge PDF documents.

What is PDFSharp API for .NET?

PDFsharp is an open-source .NET library designed for creating and processing PDF documents with ease and flexibility. Whether you're generating new PDFs from scratch, merging existing documents, or adding text, images, and shapes to PDFs, PDFsharp provides a wide array of functionalities. It allows .NET developers to handle PDF files programmatically with a clear and intuitive API, making it an excellent choice for both small-scale applications and large enterprise solutions. Its ability to work with both vector and raster graphics in PDF documents makes it a versatile tool for generating complex reports or dynamic content in .NET applications.

PDFSharp for .NET API - Key Features

Following are some of the main features of PDFSharp:

  • Create new PDF documents from scratch.
  • Modify existing PDF documents.
  • Add text, images, and graphics to PDF pages.
  • Supports vector graphics and raster images.
  • Merge or split PDF documents.
  • Extract content from PDF files.
  • Handle fonts, including TrueType fonts.
  • Draw shapes like lines, rectangles, and circles.
  • Supports encrypted PDF files.
  • Generate PDF/A documents for archiving.
  • Compatible with .NET Framework and .NET Core.
These features highlight the capabilities and benefits of using PDFSharp API for .NET in PDF document creation and manipulation.
GitHub

GitHub Stats

Name:
Language:
Stars:
Forks:
License:
Repository was last updated at

Getting Started with PDFSharp for .NET API

You can download the ShapeCrawler library from GitHub or nuget.

Installation

Installing PDFSharp API for .NET is simple and can be done from nugget as shown below:

Installing PDFSharp API for .NET


 Install-Package PdfSharp

Code Examples for PdfSharp API for .NET

PDFSharp API is a powerful .NET API that can be used to work with PDF documents from within your .NET applications. It doesn't require you to understand the underlying structure of PDF files in order to work with PDF documents. PDFSharp can be used by programming in all .NET languages such as C# and VB.NET. Let's jump into some code samples for working with PDF files using the PDFSharp API for .NET.

How to Create a blank PDF file using PDFSharp API for .NET?

In order to create a PDF document using the PDFSharp API for .NET, the following steps can help.

  • Create a new PDF document: This initializes an empty PDF document.
  • Add a new page: Adds a blank page to the document.
  • Draw text: Uses the XGraphics object to write "Hello, World!" at the center of the page.
  • Save the document: Saves the PDF with the specified filename.

How to add Image to a PDF using PDFSharp API?

PDFSharp lets you create a PDF document and insert image into it from your .NET application. You can use the following steps to create a PDF document with image.

  • Create a new PDF document: This initializes an empty PDF document.
  • Add a page: Adds a blank page to the document.
  • Load the image: Uses XImage.FromFile() to load an image from the specified file path.
  • Draw the image: Uses gfx.DrawImage() to position and resize the image on the PDF page.
  • Save the document: Saves the PDF with the image.

How to Insert Table in a PDF document in .NET?

To insert a table in a PDF document using the PDFSharp for .NET API, you can follow these steps.

  • Create a new PDF document: This initializes an empty PDF document.
  • Add a page: Adds a blank page to the new PDF document.
  • Define the rows and columns to be part of the table.
  • Use nested loops to create the table using the number of rows and columns.
  • Save the document: Saves the PDF with the image.

Add Watermark to a PDF Page in .NET

To add a watermark to a PDF page using the PDFSharp for .NET API, you can use the following steps.

  • Load an existing PDF document: The code opens an existing PDF in modify mode.
  • Loop through pages: It iterates over each page in the document.
  • Create an XGraphics object: Allows drawing operations on the PDF page.
  • Define watermark properties such as font and text.
  • Draw the watermark: The text is centered across the page with a diagonal layout.
  • Save the document: Saves the PDF with the watermark applied.

Conclusion

PDFsharp is a versatile and powerful open-source library for .NET developers, offering comprehensive tools for creating, editing, and managing PDF documents. With its straightforward API, PDFsharp simplifies various PDF operations, from generating new documents and adding images or text to modifying existing PDFs by overlaying content like watermarks. It supports vector graphics, shapes, tables, and hyperlinks, making it suitable for a wide range of applications, including report generation, document processing, and archiving. Its compatibility with .NET Framework and .NET Core further extends its usability across different platforms, making PDFsharp a reliable choice for PDF handling in .NET projects.

Similar Products

 English