Aspose.Pdf for .NET is a popular tool that can be used to create PDF documents. It helps you to create and manipulate PDF documents in .NET with ease. Most importantly, you can leverage Aspose.Pdf to manipulate existing PDF documents sans the need of having Adobe Acrobat installed in your system. This article provides an overview of Aspose.Pdf and how we can work with it in .NET applications.
Aspose.Pdf provides many interesting features. Some of the important features include the following:
- Compression of PDF documents
- Add or remove bookmarks
- Support for graphs, fonts and hyperlinks
- Convert pages to images
- Print PDF documents
- Import and Export PDF from data
- Encrypt or decrypt PDF documents
- Digitally sign PDF documents
You can install Aspose.Pdf for .NET via NuGet Package Manager. To install Aspose.Pdf you can run the following command in the Package Manager Console.
PM> Install-Package Aspose.Pdf
Getting Started with Aspose.Pdf in Visual Studio
In this section, we will explore how we can work with Aspose.Pdf in .NET. We will learn how to create a PDF document using the Aspose.Pdf API.
Here's the list of the steps that you would need to follow to create a PDF document using the Aspose API for .NET.
- Open Visual Studio 2017 (I'm using Visual Studio 2017 in my system though you can use the earlier versions, i.e., Visual Studio 2015 or Visual Studio 2013 as well)
- Create a new C# console application project
- Save the project with a name
- Next, create an instance of the Pdf class (this class is available as part of the Aspose.Pdf.Generator) namespace
- Specify the license (if you have purchased a license) using the License class
- Add one or more sections to the Pdf object. Note that the Sections collection is used to hold one or more sections.
- Add a text paragraph to the section you just created
- Lastly, call the Save method on the Pdf instance to generate your PDF document
And that's all you need to do to create a PDF document using the Aspose.Pdf API.
Applying the License
Applying the license to the Aspose.Pdf is simple. All you need to do is create an instance of the Aspose.Pdf.License class, call the SetLicense method and pass the license file name as a parameter to the method.
The easiest way to apply the license to Aspose.Pdf component is by placing the license file inside the same directory where the Aspose.dll resides. This way you would not have to have the hassle of passing path while specifying the license file name to the SetLicense method. The following code snippet shows how you instantiate the License class, load the license from a license file and then make a call to the SetLicense method to apply the license.
Aspose.Pdf.License license = new Aspose.Pdf.License();
Learn more about how to work with Aspose.Pdf from here.
If you would like to explore more on Aspose.Pdf or on any of the Aspose family of products, you can refer to their documentation.
The Complete Code Listing
The following code listing illustrates how you can create a new PDF document using the Aspose.Pdf API.
private static void Main(string args)
//Create an instance of Pdf class
var pdf = new Pdf.Generator.Pdf();
//Specify the license to be used
var license = new License();
// Now, add a section into the pdf document
var customSection = pdf.Sections.Add();
// Next, add a text paragraph to the section just created
customSection.Paragraphs.Add(new Text("This is a sample text"));
// Save the document - this generates the document as well
// The saved document is stored in the path mentioned
Note that the following namespaces should be included in your program for it to compile and work.
Aspose.Pdf for .NET is a popular PDF document creation component that you can use from within your .NET applications to create, edit and manage PDF documents without the need of having Acrobat installed in your system. This article presented a discussion on Aspose.Pdf, its incredible features and how you can get started using it in our .NET applications. Happy reading!