Referencing the Assembly and Deployment
The easiest way to reference and deploy DynamicPDF Rasterizer in your project is by installing the NuGet package from directly within Visual Studio's Package Manager. Alternatively, you can follow the instructions here to reference and deploy the assembly manually.
NOTE: We recommend installing using the NuGet package, as this is the easiest and least error-prone installation method.
Referencing NuGet Package
You can install the NuGet package directly in Visual Studio's Package Manager.
- NuGet: ceTe.DynamicPDF.Rasterizer.NET (https://www.nuget.org/packages/ceTe.DynamicPDF.Rasterizer.NET)
Manual Installation
You can install the assemblies manually by downloading the appropriate zip file from the DynamicPDF website. The downloaded ZIP file contains two assemblies, one for each .NET Framework 4.0 and one for .NET Standard 2.0.
Ensure that you use the appropriate target platform the appropriate DynamicPDF DLL is referenced and deployed with your application based on the Target Platform. Also review what versions of each platform are supported in the Supported Platforms topic.
The following table provides details of each assembly.
Assembly Name | Assembly Version | .NET Framework Version | Platform |
---|---|---|---|
net40\DynamicPDF.Rasterizer.dll | 3.x.x | 4.x | AnyCPU |
netstandard20\DynamicPDF.Rasterizer.dll | 3.x.x | NET Standard 2.0 | AnyCPU |
Adding assembly reference by selecting “Add Reference”
To reference our assembly from Visual Studio, open your project's references window (right click on the project's References and select "Add Reference..."). From the Add Reference window click on the "Browse" tab and browse to the bin folder in the extracted content and select the appropriate DLL based on the platform target of the project (see above table).
NOTE: The accompanying xml files are used by IntelliSense and are not redistributed with your finished application.
Deployment
The Native files that must accompany the .NET assemblies are listed in the following table. For the .NET Standard assembly, the Microsoft Visual C++ 2017 Redistributable is required and are installed with Visual Studio or can also be downloaded from Microsoft. The .NET Framework 4.x has no such dependency.
Assembly | .NET Framework | Native Files | Comments |
---|---|---|---|
net40\DynamicPDF.Rasterizer.dll | .NET Framework 4.x | Windows\DPDFRenderNative_XXX.dll | |
netstandard20\DynamicPDF.Rasterizer.dll | .NET Framework 4.x, .NET Core (on Windows), Mono (on Windows) | DPDFRenderNative\Windows\DPDFRenderNative_XXX.dll | Visual C++ Redistributable for Visual Studio 2017 Required |
netstandard20\DynamicPDF.Rasterizer.dll | UWP | DPDFRenderNative\UWP\DPDFRenderNative_XXX.dll | Visual C++ Redistributable for Visual Studio 2017 Required |
netstandard20\DynamicPDF.Rasterizer.dll | Linux | DPDFRenderNative\Linux\libDPDFRenderNative_x64.so | Visual C++ Redistributable for Visual Studio 2017 Required |
Licensing
Although you can use the evaluation edition of DynamicPDF Rasterizer, images created include a watermark. You must add a license key to remove the watermark. After purchasing an appropriate serial number, retrieve the license keys from the Customer Area of DynamicPDF's website: https://www.dynamicpdf.com/CustomerArea. Then add the license key to either a .config file or programmatically within your application.
.NET Core (Windows) / Mono (Windows) Deployment
The native file(s) DPDFRenderNative_XXX.dll (there is one for x86, x64) must be deployed along with the DynamicPDF.Rasterizer.dll if developing a .NET Core/Mono project. These files are located in the "bin\DPDFRenderNative\Windows" folder in the downloaded zip file.
.NET Core (Linux) / Mono (Linux)Deployment
Mono projects targeting Linux require adding the native file libDPDFRenderNative_XXX.so to your project and must be deployed along with the DynamicPDF.Rasterizer.dll. The DPDFRenderNative.XXX.so file is located in the "bin\DPDFRenderNative\Linux" folder in the downloaded zip file.
NOTE: Currently only x64 process architecture library is provided for .NET Core projects.
UWP Deployment
UWP projects require adding the native file DPDFRenderNative_XXX.dll (there is one for x86, x64) to your project. Set the "Build Action" property to "Content" and deployed it along with the DynamicPDF.Rasterizer.dll. These files are located in the "bin\DPDFRenderNative\UWP" folder in the downloaded zip file.
Loading Native libraries
The Native DLLs for DynamicPDF Rasterizer can be deployed by setting the current directory using the SetCurrentDirectory or SetDllDirectory methods. Both deployment methods are describe as follows.
Using SetCurrentDirectory
The following code deploys the native dlls using the SetCurrentDirectory method.
String defaultCurrentDir = System.IO.Directory.GetCurrentDirectory();
//Set the current directory and load the native DLL file.
System.IO.Directory.SetCurrentDirectory(@"Folder path");
PdfRasterizer rasterizer = New PdfRasterizer(pdfFilePath);
//Once the native DLL is loaded you can change it back to original.
System.IO.Directory.SetCurrentDirectory(defaultCurrentDir);
rasterizer.Draw(pngFilePath, ImageFormat.Png, ImageSize.Dpi72);
Dim MyDefaultCurrentDir As String = System.IO.Directory.GetCurrentDirectory()
'Set the current directory and load the native DLL file.
System.IO.Directory.SetCurrentDirectory("Folder path")
Dim MyRasterizer As PdfRasterizer = New PdfRasterizer(PdfFilePath);
'Once the native DLL is loaded you can change it back to original.
System.IO.Directory.SetCurrentDirectory(MyDefaultCurrentDir)
MyRasterizer.Draw(PngFilePath, ImageFormat.Png, ImageSize.Dpi72)
Using SetDllDirectory
The following code deploys the native dlls using the SetDllDirectory method.
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool SetDllDirectory(string PathName);
static void Main(string[] args)
{
SetDllDirectory(@"Native Assembly Path");
int err = Marshal.GetLastWin32Error();
PdfRasterizer rasterizer = New PdfRasterizer(pdfFilePath);
rasterizer.Draw(pngFilePath, ImageFormat.Png, ImageSize.Dpi72);
}
<DllImport("kernel32.dll", CharSet:=CharSet.Unicode, SetLastError:=True)>
Function SetDllDirectory(ByVal lpPathName As String) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
Sub Main(ByVal args() As String)
SetDllDirectory("Native Assembly Path")
Dim ErrorMsg As String = New System.ComponentModel.Win32Exception(Marshal.GetLastWin32Error()).Message
Console.WriteLine(ErrorMsg)
Dim MyRasterizer As PdfRasterizer = New PdfRasterizer(PdfFilePath);
MyRasterizer.Draw(PngFilePath, ImageFormat.Png, ImageSize.Dpi72)
End Sub