How can I use a HTML to PDF .NET Library from a C++ Native Windows Application

Posted by in C# category on for Advance level | Points: 250 | Views : 6982 red flag

There are 2 possible approaches to use the html to pdf converter in a non .NET application, assuming you have a Windows server which are discussed in this article.


How can I use a HTML to PDF .NET Library from a C++ Native Windows Application? There could be 2 approaches
1. You can create a simple ASP.NET application with only one page which receives an URL in query string and converts that URL to PDF and returns the resulted PDF in HTTP response. From your application (Pearl, PHP etc) you can redirect to that ASP.NET page giving the URL you want to convert in query string. To create the application you can modify our sample for ASP.NET to produce the PDF in PageLoad even handler instead of converting to PDF when a button is pressed
2. If you can use COM in your  application, this article explains how to use the .NET library in a C++ application:v
For example HiQPdf library is a .NET library and it cannot be referenced directly into a native Windows application. 


You can register the HiQPdf classes for COM clients and produce a type library file by executing the following command in an Administrator command prompt: 

regasm HiQPdf.dll /tlb:HiQPdf.tlb 

The HiQPdf.tlb will be included in the C++ application code to offer the prototypes for HiQPdf classes and methods. The compiler will produce a C++ header file named HiQPdf.tlh from the TLB file, containing the HiQPdf library types and methods prototypes. 

The HiQPdf.dll and HiQPdf.dep files must be copied near the application executable or otherwise you have to install the HiQPdf.dll in GAC to make it available for COM infrastructure. 

Using the code

The C++ code of a simple console application which converts an URL and saves the resulted PDF document to a file on disk looks like below:

#include <iostream>

#import "HiQPdf.tlb" raw_interfaces_only


using namespace HiQPdf;

int main()




// create the HTML to PDF converter

_HtmlToPdfPtr htmlToPdfConverter(__uuidof(HtmlToPdf));


// get a reference to the PDF document control object from converter

_PdfDocumentControl * pdfDocumentControl;



// set PDF page orientation



// set PDF page margins

_PdfMargins* pdfMargins;







// create the URL to convert and output PDF file name strings

BSTR urlToConvert = SysAllocString(L"");

BSTR outPdfFile = SysAllocString(L"out.pdf");


// call the converter to convert the HTML document to a PDF file

htmlToPdfConverter->ConvertUrlToFile(urlToConvert, outPdfFile);


// free the allocated strings






return 0;



It is very simple to use a html to pdf  .NET library from COM clients to get quality PDFs.


Page copy protected against web site content infringement by Copyscape

About the Author

Full Name: stevnetk stevnetk
Member Level: Starter
Member Status: Member
Member Since: 3/13/2012 4:07:32 PM
Country: United States

Login to vote for this post.

Comments or Responses

Login to post response

Comment using Facebook(Author doesn't get notification)