How to call html to pdf asp.net library from a C++ Native Windows Application

You can use hiqpdf html to pdf asp.net library from a c# application. First you should register the HiQPdf classes for COM clients and produce a type library file by executing the following command in 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:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#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;

}

Topic archived. No new replies allowed.