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.

Manual Installation

DynamicPDF Rasterizer v3.11 For .NET assemblies are installed at "%ProgramFiles%\DynamicPDF Rasterizer v3.x.x for .NET\bin" on 32-bit computers and "%ProgramFiles(x86)%\DynamicPDF Rasterizer v3.08 for .NET\bin" on 64-bit computers by default. The following table provides details of each assembly.

Assembly Name Assembly Version .NET Framework Version Platform
DynamicPDF.Rasterizer.NETFramework40.dll 3.x.x 4.x AnyCPU
DynamicPDF.Rasterizer.NETStandard20.dll 3.x.x NET Standard 2.0 AnyCPU

Adding assembly reference by selecting “Add Reference”

To reference the assembly within Visual Studio, open your project's references window (right click on the project and select "Add Reference..."). Then, from the Add Reference window, select "DynamicPDF Rasterizer for .NET (Framework 4.x)" from the list on the ".NET" tab. Select OK to complete adding the assembly.

By default DynamicPDF Rasterizer is installed at the following location.

NOTE: Do not add multiple assemblies to your applications bin folder. Adding multiple assemblies can cause errors and yield unpredictable results. Also note that 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
DynamicPDF.Rasterizer.NETFramework40.dll .NET Framework 4.x Windows\DPDFRenderNative_XXX.dll
DynamicPDF.Rasterizer.NETStandard20.dll .NET Framework 4.x, .NET Core (on Windows), Mono (on Windows) Windows\DPDFRenderNative_XXX.dll Visual C++ Redistributable for Visual Studio 2017 Required
DynamicPDF.Rasterizer.NETStandard20.dll UWP UWP\DPDFRenderNative_XXX.dll Visual C++ Redistributable for Visual Studio 2017 Required
DynamicPDF.Rasterizer.NETStandard20.dll Linux 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.NETStandard20.dll if developing a .NET Core/Mono project. These files are located in the "bin\Native\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.NETStandard20.dll. The DPDFRenderNative.XXX.so file is located in the "bin\Native\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.NETStandard20.dll. These files are located in the "bin\Native\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 

In this topic