PDF rendering with external graphic engines

XFINIUM.PDF 6.4 brings support for using external graphic engines, such as GDI+ or Skia, when rendering PDF files.

The XFINIUM.PDF rendering library includes its own graphic engine for rendering PDF files. This means that we implemented path stroking and filling, gradients, image drawing, etc from scratch. The advantage is that the rendering engine is fully portable and the results are identical on all platforms. The drawback is that in some situations the rendering engine can be slow. Because of this we added support for external graphic engines which take the task of drawing and filling paths, drawing images etc thus improving the rendering speed.

As we had to implement interfaces for each graphic engine on each platform, not all graphic engines are available for all platforms. WinForms / ASP.NET support GDI+ and Skia, WPF supports GDI+ and Skia, UWP supports Win2D, Xamarin.Android supports Skia and Xamarin.iOS supports CoreGraphics.

These graphic engines are available as addon to XFINIUM.PDF Professional Editions and can be downloaded here. They are not included in the main install kits because they are optional and we did not want to increase the size of the main install kits. The evaluation version downloads include everything you need to get started and see how to render a PDF page using the external engine but we recommend to download also the full install kits in order to get the complete samples and help files.

WinForms / ASP.NET

GDI+ graphic engine

The graphic renderer based on GDI+ engine is implemented in Xfinium.Graphics.Win.Gdi.dll assembly (located in the Redist folder).
Add a reference in your project to Xfinium.Graphics.Win.Gdi.dll (besides Xfinium.Pdf.Win.dll and Xfinium.Pdf.Render.Win.dll) and in your code add this line after creating the PdfPageRenderer object:
C#:

// renderer is a PdfPageRenderer object
renderer.GraphicRenderer = new Xfinium.Graphics.Gdi.GdiRenderer();

VB.NET:

' renderer is a PdfPageRenderer object
renderer.GraphicRenderer = New Xfinium.Graphics.Gdi.GdiRenderer()

Only the PdfArgbIntRenderingSurface and PdfBgraByteRenderingSurface surfaces are supported by the GDI+ graphic engine.

Please see PDFToImage sample (included in graphic engine install archive, not the main install kit) for more details.

If you choose to use the GDI+ graphic renderer in your application, you need to deploy the Xfinium.Graphics.Win.Gdi.dll along with Xfinium.Pdf.Win.dll and Xfinium.Pdf.Render.Win.dll.
The Xfinium.Pdf.Win.dll and Xfinium.Pdf.Render.Win.dll assemblies included in Redist folder are the same ones included in the main install kit.

Skia graphic engine

The graphic renderer based on SkiaSharp engine is implemented in Xfinium.Graphics.Win.Skia.dll assembly (located in the Redist folder).
Add a reference in your project to Xfinium.Graphics.Win.Skia.dll (besides Xfinium.Pdf.Win.dll and Xfinium.Pdf.Render.Win.dll) and in your code add this line after creating the PdfPageRenderer object:
C#:

// renderer is a PdfPageRenderer object
renderer.GraphicRenderer = new Xfinium.Graphics.Skia.SkiaRenderer();

VB.NET:

' renderer is a PdfPageRenderer object
renderer.GraphicRenderer = New Xfinium.Graphics.Skia.SkiaRenderer()

In your application’s project file add these sections:

<!-- add the native x86 Windows library -->
<ItemGroup Condition="'$(Platform)' == 'x86'">
  <None Include="..Redistx86libSkiaSharp.dll">
    <Link>libSkiaSharp.dll</Link>
    <CopyToOutputDirectory>Always</CopyToOutputDirectory>
  </None>
</ItemGroup>
<!-- add the native x64 Windows library -->
<ItemGroup Condition="'$(Platform)' == 'x64'">
  <None Include="..Redistx64libSkiaSharp.dll">
    <Link>libSkiaSharp.dll</Link>
    <CopyToOutputDirectory>Always</CopyToOutputDirectory>
  </None>
</ItemGroup>

Update the value of ‘Include’ attributes with the actual paths to the libSkiaSharp.dll. Your application needs to be compiled for x86 or x64 (AnyCPU will not work) in order for the correct libSkiaSharp.dll to be copied in the output folder.

Only the PdfArgbIntRenderingSurface and PdfBgraByteRenderingSurface surfaces are supported by the Skia graphic engine.

Please see PDFToImage sample (included in graphic engine install archive, not the main install kit) for more details.

If you choose to use the Skia graphic renderer in your application, you need to deploy the Xfinium.Graphics.Win.Skia.dll, SkiaSharp.dll, libSkia.dll (x86libSkiaSharp.dll for 32bit apps, x64libSkiaSharp.dll for 64bit apps) along with Xfinium.Pdf.Win.dll and Xfinium.Pdf.Render.Win.dll.
Make sure the Microsoft Visual C++ 2015 Redistributable is installed if this error occurs: Unable to load DLL ‘libSkiaSharp.dll’: The specified module could not be found.
The Skia graphic renderer requires .NET 4.5 or higher.

The Xfinium.Pdf.Win.dll and Xfinium.Pdf.Render.Win.dll assemblies included in Redist folder are the same ones included in the main install kit.

WPF

GDI+ graphic engine

The graphic renderer based on GDI+ engine is implemented in Xfinium.Graphics.Wpf.Gdi.dll assembly (located in the Redist folder).
Add a reference in your project to Xfinium.Graphics.Wpf.Gdi.dll (besides Xfinium.Pdf.Wpf.dll and Xfinium.Pdf.Render.Wpf.dll) and in your code add this line after creating the PdfPageRenderer object:
C#:

// renderer is a PdfPageRenderer object
renderer.GraphicRenderer = new Xfinium.Graphics.Gdi.GdiRenderer();

VB.NET:

' renderer is a PdfPageRenderer object
renderer.GraphicRenderer = New Xfinium.Graphics.Gdi.GdiRenderer()

Only the PdfArgbIntRenderingSurface and PdfBgraByteRenderingSurface surfaces are supported by the GDI+ graphic engine.

Please see PDFToImage sample (included in graphic engine install archive, not the main install kit) for more details.

If you choose to use the GDI+ graphic renderer in your application, you need to deploy the Xfinium.Graphics.Wpf.Gdi.dll along with Xfinium.Pdf.Wpf.dll and Xfinium.Pdf.Render.Wpf.dll.

The Xfinium.Pdf.Wpf.dll and Xfinium.Pdf.Render.Wpf.dll assemblies included in Redist folder are the same ones included in the main install kit.

Skia graphic engine

The graphic renderer based on SkiaSharp engine is implemented in Xfinium.Graphics.Wpf.Skia.dll assembly (located in the Redist folder).
Add a reference in your project to Xfinium.Graphics.Wpf.Skia.dll (besides Xfinium.Pdf.Wpf.dll and Xfinium.Pdf.Render.Wpf.dll) and in your code add this line after creating the PdfPageRenderer object:
C#:

// renderer is a PdfPageRenderer object
renderer.GraphicRenderer = new Xfinium.Graphics.Skia.SkiaRenderer();

VB.NET:

' renderer is a PdfPageRenderer object
renderer.GraphicRenderer = New Xfinium.Graphics.Skia.SkiaRenderer()

In your application’s project file add these sections:

<!-- add the native x86 Windows library -->
<ItemGroup Condition="'$(Platform)' == 'x86'">
  <None Include="..Redistx86libSkiaSharp.dll">
    <Link>libSkiaSharp.dll</Link>
    <CopyToOutputDirectory>Always</CopyToOutputDirectory>
  </None>
</ItemGroup>
<!-- add the native x64 Windows library -->
<ItemGroup Condition="'$(Platform)' == 'x64'">
  <None Include="..Redistx64libSkiaSharp.dll">
    <Link>libSkiaSharp.dll</Link>
    <CopyToOutputDirectory>Always</CopyToOutputDirectory>
  </None>
</ItemGroup>

Update the value of ‘Include’ attributes with the actual paths to the libSkiaSharp.dll. Your application needs to be compiled for x86 or x64 (AnyCPU will not work) in order for the correct libSkiaSharp.dll to be copied in the output folder.

Only the PdfArgbIntRenderingSurface and PdfBgraByteRenderingSurface surfaces are supported by the Skia graphic engine.

Please see PDFToImage sample (included in graphic engine install archive, not the main install kit) for more details.

If you choose to use the Skia graphic renderer in your application, you need to deploy the Xfinium.Graphics.Wpf.Skia.dll, SkiaSharp.dll, libSkia.dll (x86libSkiaSharp.dll for 32bit apps, x64libSkiaSharp.dll for 64bit apps) along with Xfinium.Pdf.Wpf.dll and Xfinium.Pdf.Render.Wpf.dll.

Make sure the Microsoft Visual C++ 2015 Redistributable is installed if this error occurs: Unable to load DLL ‘libSkiaSharp.dll’: The specified module could not be found.
The Skia graphic renderer requires .NET 4.5 or higher.

The Xfinium.Pdf.Wpf.dll and Xfinium.Pdf.Render.Wpf.dll assemblies included in Redist folder are the same ones included in the main install kit.

UWP

Win2D graphic engine

The graphic renderer based on Win2D engine is implemented in Xfinium.Graphics.Uwp.Win2D.dll assembly (located in the Redist folder).
Add a reference in your project to Xfinium.Graphics.Uwp.Win2D.dll (besides Xfinium.Pdf.Uwp.dll and Xfinium.Pdf.Render.Uwp.dll) and in your code add this line after creating the PdfPageRenderer object:
C#:

// renderer is a PdfPageRenderer object
renderer.GraphicRenderer = new Xfinium.Graphics.Win2D.Win2DRenderer();

VB.NET:

' renderer is a PdfPageRenderer object
renderer.GraphicRenderer = New Xfinium.Graphics.Win2D.Win2DRenderer()

In your application’s project file add these sections:

<PropertyGroup>
  <win2d-Platform Condition="'$(Platform)' == 'Win32'">x86</win2d-Platform>
  <win2d-Platform Condition="'$(Platform)' != 'Win32'">$(Platform)</win2d-Platform>
</PropertyGroup>
<ItemGroup Condition="'$(TargetPlatformIdentifier)' == 'UAP'">
  <Reference Include="..redistMicrosoft.Graphics.Canvas.winmd">
    <Implementation>Microsoft.Graphics.Canvas.dll</Implementation>
  </Reference>
  <ReferenceCopyLocalPaths Include="..redistwin10-$(win2d-Platform)Microsoft.Graphics.Canvas.dll" />
</ItemGroup>

Update the value of ‘Include’ attributes with the actual paths to the Microsoft.Graphics.Canvas.winmd and Microsoft.Graphics.Canvas.dll. Your application needs to be compiled for x86, x64 or ARM (AnyCPU will not work) in order for the correct Microsoft.Graphics.Canvas.dll to be copied in the output folder.

Only the PdfArgbIntRenderingSurface and PdfBgraByteRenderingSurface surfaces are supported by the Skia graphic engine.

Please see PDFToImage sample (included in graphic engine install archive, not the main install kit) for more details.

If you choose to use the Win2D graphic renderer in your application, you need to deploy the Xfinium.Graphics.Uwp.Win2D.dll, Microsoft.Graphics.Canvas.winmd, Microsoft.Graphics.Canvas.dll

(win10-armMicrosoft.Graphics.Canvas.dll for ARM apps, win10-x86Microsoft.Graphics.Canvas.dll for 32bit apps, win10-x64Microsoft.Graphics.Canvas.dll for 64bit apps) along with Xfinium.Pdf.Uwp.dll and Xfinium.Pdf.Render.Uwp.dll.

The Xfinium.Pdf.Uwp.dll and Xfinium.Pdf.Render.Uwp.dll assemblies included in Redist folder are the same ones included in the main install kit.

Xamarin.Android

Skia graphic engine

The graphic renderer based on SkiaSharp engine is implemented in Xfinium.Graphics.Xamarin.Android.Skia.dll assembly (located in the Redist folder).
Add a reference in your project to Xfinium.Graphics.Xamarin.Android.Skia.dll (besides Xfinium.Pdf.Xamarin.Android.dll and Xfinium.Pdf.Render.Xamarin.Android.dll) and in your code add this line after creating the PdfPageRenderer object:
C#:

// renderer is a PdfPageRenderer object
renderer.GraphicRenderer = new Xfinium.Graphics.Skia.SkiaRenderer();

Only the PdfRgbaIntRenderingSurface and PdfRgbaByteRenderingSurface surfaces are supported by the Skia graphic engine.

Please see PDFToImage sample (included in graphic engine install archive, not the main install kit) for more details.

If you choose to use the Skia graphic renderer in your application, you need to deploy the Xfinium.Graphics.Xamarin.Android.Skia.dll, SkiaSharp.dll along with Xfinium.Pdf.Xamarin.Android.dll and Xfinium.Pdf.Render.Xamarin.Android.dll.

The Xfinium.Pdf.Xamarin.Android.dll and Xfinium.Pdf.Render.Xamarin.Android.dll assemblies included in Redist folder are the same ones included in the main install kit.

Xamarin.iOS

CoreGraphics graphic engine

The graphic renderer based on CoreGraphics engine is implemented in Xfinium.Graphics.Xamarin.iOS.CoreGraphics.dll assembly (located in the Redist folder).
Add a reference in your project to Xfinium.Graphics.Xamarin.iOS.CoreGraphics.dll (besides Xfinium.Pdf.Xamarin.iOS.dll and Xfinium.Pdf.Render.Xamarin.iOS.dll) and in your code add this line after creating the PdfPageRenderer object:
C#:

// renderer is a PdfPageRenderer object
renderer.GraphicRenderer = new Xfinium.Graphics.CoreGraphics.CoreGraphicsRenderer();

Only the PdfRgbaByteRenderingSurface surface is supported by the CoreGraphics graphic engine.

Please see PDFToImage sample (included in graphic engine install archive, not the main install kit) for more details.

If you choose to use the CoreGraphics graphic renderer in your application, you need to deploy the Xfinium.Graphics.Xamarin.iOS.CoreGraphics.dll along with Xfinium.Pdf.Xamarin.iOS.dll and Xfinium.Pdf.Render.Xamarin.iOS.dll.

The Xfinium.Pdf.Xamarin.iOS.dll and Xfinium.Pdf.Render.Xamarin.iOS.dll assemblies included in Redist folder are the same ones included in the main install kit.

2 thoughts on “PDF rendering with external graphic engines”

  1. There is no user friendly document I found throughout the tutorials…. If I am following 1 example and then I want to integrate another one then Its not working. Can you pls give us an example In which we can render pdf page by page and also we can jump directly on a page example: let say now I am on 10th page and I can jump directly on 101th page.

    Thanks.

    1. You simply create a PdfPageRenderer for the page you want to convert to image:
      PdfPageRenderer renderer1 = new PdfPageRenderer(pdfFixedDocument.Pages[9]); // renderer for the 10th page (zero based index)
      PdfPageRenderer renderer2 = new PdfPageRenderer(pdfFixedDocument.Pages[100]); // renderer for the 101th page (zero based index)

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: