Converting HTML to PDF with IE9+ correctly

By default, you get raster image instead of PDF objects when converting certain HTML webpages to PDF on PCs that have IE9 installed. This is because our component uses the Internet Explorer control to render HTML code and then convert to PDF objects and IE9 uses DirectX to render webpages instead of GDI as mentioned in IViewObject Legacy Drawing section by default.

To allow the component to convert HTML to PDF correctly, you need to turn off the DirectX feature in IE9 by setting the key FEATURE_IVIEWOBJECTDRAW_DMLT9_WITH_GDI to 0.

HKEY_LOCAL_MACHINE (or HKEY_CURRENT_USER)
   SOFTWARE
      Microsoft
         Internet Explorer
            Main
               FeatureControl
                  FEATURE_IVIEWOBJECTDRAW_DMLT9_WITH_GDI
                     contoso.exe = (DWORD) 00000000

contoso.exe is your application executable file.

Update:

From version 7.0, you can convert any modern HTML webpage to PDF using the HtmlToPdfConverter class. It uses the native library instead of IE COM interfaces to render HTML pages. With that improvement, the Ultimate PDF can handle HTML 5 webpages with CSS 3, SVG, and Web fonts better than the previous versions.

To get started with the new converter engine, download the Ultimate PDF, install it and browse folder <InstallDir>\Samples\Pdf\Win\CS\Html To Pdf and Image. You will see there are two examples. One is for converting HTML to PDF, and the other one is for HTML to Image conversion. Both projects have similar basic settings. The HTML one is more advanced. We will walk through some steps below to show you how to convert webpages.

Create a new instance of the HtmlToPdfConverter class

var c = new HtmlToPdfConverter()
{
    ViewportWidth = Width,
    ViewportHeight = Height,
    PageSize = PageSize,
    PageMargin = Margin,
    Portrait = Portrait,
    Delay = ConversionDelay,
    Timeout = Timeout,

    SinglePage = SinglePage
};

Here we have serveral options:

  • ViewportWidth is the browser viewport width
  • ViewportHeight is the browser viewport height
  • PageSize is the PDF page size
  • PageMargin is the margin of the PDF page
  • Portrait is the orientation of the PDF page
  • Delay is the time delay before starting the conversion
  • Timeout is the conversion timeout

45-Day Money Back Guarantee

We will refund your full money in 45 days
if you are not satisfied with our products

Buy Now

Dont miss out Get update on new articles and other opportunities