Call html to pdf .net Library from a C++ Native Windows Application

Using the HiQPDF [link=http://www.hiqpdf.com]html to pdf[/link] conversion engine you can easily design a document in HTML with CSS3, JavaScript, SVG or Canvas and then convert it to PDF preserving the exact content and style.

HiQPdf library is a powerful and precise .NET library that you can call from a C++ Native Windows Application.

First you should 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. 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

#include

#import "HiQPdf.tlb" raw_interfaces_only

using namespace HiQPdf;

int main()

{

CoInitialize(0);

{

// create the HTML to PDF converter

_HtmlToPdfPtr htmlToPdfConverter(__uuidof(HtmlToPdf));

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

_PdfDocumentControl * pdfDocumentControl;

htmlToPdfConverter->get_Document(&pdfDocumentControl);

// set PDF page orientation

pdfDocumentControl->put_PageOrientation(PdfPageOrientation_Portrait);

// set PDF page margins

_PdfMargins* pdfMargins;

pdfDocumentControl->get_Margins(&pdfMargins);

pdfMargins->put_Left(10);

pdfMargins->put_Right(10);

pdfMargins->put_Top(10);

pdfMargins->put_Bottom(10);

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

BSTR urlToConvert = SysAllocString(L"enter here theURL address");

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

SysFreeString(urlToConvert);

SysFreeString(outPdfFile);

}

CoUninitialize();

return 0;

}

The HTML to PDF, HTML to SVG and HTML to Image converters included in the HiQPdf library for .NET can be used to create high quality PDF documents, SVG vector images and transparent PNG images.

You can download the [link=http://www.hiqpdf.com]html to pdf[/link] demo applications for HiQPDF Library with source code in C# and VB

Comments

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories