How to Install Aspose.PDF for .NET
Aspose.PDF C# component
Product Description
Aspose.PDF for .NET is a robust .NET component that lets developers create PDF documents from scratch without using Adobe Acrobat. It provides a simple Application Programming Interface (API) that is easy to learn and use.
Aspose.PDF for .NET is implemented using Managed C# and it can be used with any .NET language like C#, VB.NET and J# etc. It can be integrated with any kind of application either it’s an ASP.NET Web Application or a Windows Application.
So that the developers can get up and running quickly, Aspose.PDF for .NET provides fully featured demos and working examples written in C#. Using these demos, developers can quickly learn about the features provided by Aspose.PDF for .NET.
The fast, light-weight component creates PDF documents efficiently and helps your application perform better. Aspose.PDF for .NET is our customers’ first choice when creating PDF documents because of its price, superb performance and great support.
Aspose.PDF for .NET is multithread safe as long as only one thread works on a document at a time. It is a typical scenario to have one thread working on one document. Different threads can safely work on different documents at the same time.
Declaration
All Aspose .NET components require Full Trust permission set. The reason is, Aspose .NET components need to access registry settings, system files other than virtual directory for certain operations like parsing fonts etc. Moreover, Aspose .NET Components are based on core .NET system classes that also require Full Trust permission set in many cases.
Internet Service Providers hosting multiple applications from different companies mostly enforce Medium Trust security level. In case of .NET 2.0, such security level applies the following constraints:
- OleDbPermission is not available. This means you cannot use the ADO.NET managed OLE DB data provider to access databases.
- EventLogPermission is not available. This means you cannot access the Windows event log.
- ReflectionPermission is not available. This means you cannot use reflection.
- RegistryPermission is not available. This means you cannot access the registry.
- WebPermission is restricted. This means your application can only communicate with an address or range of addresses that you define in the
<trust>
element. - FileIOPermission is restricted. This means you can only access files in your application’s virtual directory hierarchy. Due to the reasons specified above, Aspose .NET components cannot be used on servers granting permission set other than Full Trust.
Installation
Evaluate Aspose.PDF for .NET
You can easily download Aspose.PDF for .NET for evaluation. The evaluation download is the same as the purchased download. The evaluation version simply becomes licensed when you add a few lines of code to apply the license.
The evaluation version of Aspose.PDF (without a license specified) provides full product functionality. Still, it has two limitations: it inserts an evaluation watermark, and only the first four pages of any document can be viewed/edited.
Installing Aspose.PDF for .NET through NuGet
NuGet is a free, open source developer-focused package management system for the .NET platform intent on simplifying the process of incorporating third party libraries into a .NET application during development. It is a Visual Studio extension that makes it easy to add, remove, and update libraries and tools in Visual Studio projects that use the .NET Framework. A library or tool can easily be shared with other developers by creating a NuGet package and storing it inside a NuGet repository. When you install the package, NuGet copies files to your solution and automatically makes the necessary changes, such as adding references and changing your app.config or web.config files. If you decide to remove the library, NuGet removes files and reverses whatever changes it made to your project so that no clutter is left.
Referencing Aspose.PDF for .NET
Install package using the Package Manager Console
- Open your .NET application in Visual Studio.
- On the Tools menu, select NuGet Package Manager and then Package Manager Console.
- Type the command
Install-Package Aspose.PDF
to install the latest full release, or type the commandInstall-Package Aspose.PDF -prerelease
to install the latest release including hot fixes. - Press
Enter
.
Update package using the Package Manager Console
If you have already referenced the component through NuGet, follow these steps to update the reference to the latest version:
- Open you .NET application in Visual Studio.
- On the Tools menu, select NuGet Package Manager and then Package Manager Console.
- Type the command
Update-Package Aspose.PDF
to reference the latest full release, or type the commandUpdate-Package Aspose.PDF -prerelease
to install latest release including hot fixes.
Install Package using the Package Manager GUI
Follow these steps to reference the component using the package manager GUI:
-
Open you .NET application in Visual Studio.
-
From the Project menu select Manage NuGet Packages.
- Select Broswe tab.
-
Type Aspose.PDF into the search box to find Aspose.PDF for .NET.
-
Click Install/Update next to the latest version of Aspose.PDF for .NET.
- And click Accept in the pop up window.
Working with .NET Core DLLs in Non-Windows Environment
As Aspose.PDF for .NET provides .NET Standard 2.0 (.NET Core 2.0) support, so it can be used in Core Applications running in Linux like operating systems. We are constantly working over improving the .NET Core support in our API. However, there are some following operations which we recommend our customers to perform, in order to get better results while using features of Aspose.PDF for .NET:
Please install:
- libgdiplus package
- package with Microsoft compatible fonts: ttf-mscorefonts-installer. (e.g.
sudo apt-get install ttf-mscorefonts-installer
) These fonts should be placed in “/usr/share/fonts/truetype/msttcorefonts” directory as Aspose.PDF for .NET scans this folder on Linux like operating systems. In case operating system has other default folder/directory for fonts, you should use following line of code before performing any operation using Aspose.PDF.
Aspose.Pdf.Text.FontRepository.Sources.Add(new FolderFontSource("<user's path to ms fonts>"));
Set up Aspose.PDF for .NET in Visual Studio Code
- Install .NET SDK
- Visit the official Microsoft .NET website.
- Download the latest .NET SDK.
- Run the installer.
- Open a terminal and verify installation by running:
dotnet --version
- Install Visual Studio Code
- Go to https://code.visualstudio.com/.
- Download the appropriate version for your operating system.
- Install Required VS Code Extensions
- Open Visual Studio Code.
- Click on the Extensions view icon (square icon on the left sidebar).
- Search for and install the following extensions:
- “C#” by Microsoft
- “C# Dev Kit” by Microsoft
- “.NET Core Test Explorer” (optional, but recommended)
- Create a new .NET project
- Open Visual Studio Code
- Go to Terminal > New Terminal
- Navigate to your desired project directory
# Create a new console application
dotnet new console -n AsposePDFNetDemo
# Navigate into the project directory
cd AsposePDFNetDemo
- Add NuGet package
# Install Aspose.PDF package
dotnet add package Aspose.PDF
- Verify package installation
- Open the
.csproj
file - Confirm the Aspose.PDF package reference is added:
<ItemGroup>
<PackageReference Include="Aspose.PDF" Version="x.x.x" />
</ItemGroup>
- Create Debug Configuration
- Press Ctrl+Shift+P (Cmd+Shift+P on Mac).
- Type “>.NET: Generate Assets for Build and Debug”.
- Select your project.
- Create or modify
.vscode/launch.json
:
{
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/bin/Debug/net7.0/AsposePDFNetDemo.dll",
"args": [],
"cwd": "${workspaceFolder}",
"console": "internalConsole",
"stopAtEntry": false
}
]
}
- Write sample code Program.cs
Replace the contents of Program.cs
with:
using System;
using Aspose.Pdf;
using Aspose.Pdf.Text;
class Program
{
static void Main(string[] args)
{
// Activate your license, you can comment out these codelines to use library in Evaluation mode
var license = new License();
license.SetLicense("Aspose.PDF.NET.lic");
// Initialize a new PDF document
using (var document = new Document())
{
// Add a page to the document
var page = document.Pages.Add();
// Create a text fragment
var textFragment = new TextFragment("Hello, Aspose.PDF for .NET!");
textFragment.Position = new Position(100, 600);
// Add text to the page
page.Paragraphs.Add(textFragment);
// Save the document
document.Save("sample.pdf");
}
}
}
- Build and run
dotnet restore
dotnet build
dotnet run