Referencing the Assembly and Deployment

You can install DynamicPDF Rasterizer directly using the NuGet Package Manager or manually. You can also install DynamicPDF Rasterizer to run as a Mono application, a .NET Core application, or a UWP application.

You must install manually if installing as a Linux application.

The easiest way to reference and deploy DynamicPDF Rasterizer in your project is by installing the NuGet package directly within Visual Studio's Package Manager. Alternatively, follow the instructions here to reference and deploy the assembly manually.

We recommend installing using the NuGet package manager, as this is the easiest and least error-prone installation method.

Install Using NuGet Package Manager

Install the NuGet package directly in Visual Studio's Package Manager.

Manual Installation

If you wish manually install Rasterizer rather than using NuGet, install the assemblies manually by downloading the appropriate zip file from the DynamicPDF website. The ZIP file contains one assembly with .NET Standard 2.0 or .NET Core 2.0 or higher.

The following table provides details of the assembly.

Assembly Name Assembly Version .NET Framework Version Platform
netstandard20\DynamicPDF.Rasterizer.dll 4.x.x NET Standard 2.0 AnyCPU

You must refer to one of the following NuGet packages per the target platform.

.NETCoreApp 2.1 and Higher

Package ID Version
System.Runtime.CompilerServices.Unsafe 5.0.0
System.Text.Encoding.CodePages 5.0.0

.NETStandard 2.0 and Higher

Package ID Version
System.Buffers 4.5.1
System.Memory 4.5.4
System.Numerics.Vectors 4.5.0
System.Runtime.CompilerServices.Unsafe 5.0.0
System.Text.Encoding.CodePages 5.0.0

::danger

Using the incorrect assembly prevents your application from compiling.

Adding assembly reference by selecting “Add Reference”

To reference the Rasterizer assembly using Visual Studio, open your project's References window (right-click References and select Add Reference...). From the Add Reference window, click the Browse tab, browse to the bin folder in the extracted content, and select the DLL.

The accompanying xml files - used internally by IntelliSense - are not redistributed with your finished application.

Deployment

The following table lists the native files that must accompany the .NET assembly.

Assembly .NET Framework Native Files
netstandard20\DynamicPDF.Rasterizer.dll .NET Framework 4.x, .NET Core (on Windows), Mono (on Windows) DPDFRenderNative\Windows\DPDFRenderNative_XXX.dll
netstandard20\DynamicPDF.Rasterizer.dll UWP DPDFRenderNative\UWP\DPDFRenderNative_XXX.dll
netstandard20\DynamicPDF.Rasterizer.dll Linux DPDFRenderNative\Linux\libDPDFRenderNative_x64.so

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 a .config file or programmatically within your application.

You can evaluate DynamicPDF Rasterizer for free; however, produced images contain a watermark if Rasterizer is not licensed.

.NET Core (Windows) / Mono (Windows) Deployment

The native file(s) DPDFRenderNative_x86.dll and DPDFRenderNative_x64.dll must be deployed along with the DynamicPDF.Rasterizer.dll if developing a .NET Core/Mono project. These files are located in the:

.NET Core (Linux) / Mono (Linux)Deployment

Mono projects targeting Linux require adding the native file(s) libDPDFRenderNative_x64.so, libDPDFRenderNative_x86.so to your project and must be deployed along with the DynamicPDF.Rasterizer.dll. The DPDFRenderNative.XXX.so file(s) are located in the:

Only the x64 process architecture library is currently provided for .NET Core projects.

UWP Deployment

UWP projects require adding the native file DPDFRenderNative_x86.dll or DPDFRenderNative_x64.dll to your project, depending upon your platfom.

To deploy, set the Build Action property to Content and deploy it along with the DynamicPDF.Rasterizer.dll. These files are located in the:

Loading Native libraries

Deploy the Native DLLs for DynamicPDF Rasterizer by setting the current directory using the SetCurrentDirectory or SetDllDirectory methods. Examples of both are illustrated in the following code examples.

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 

In this topic