Important alert: (current site time 5/21/2013 6:00:00 PM EDT)
 

VB icon

How to call the HiQPDF HTML to PDF .NET Library from a C++ Native Windows Application

Email
Submitted on: 7/9/2012 5:48:30 PM
By: Stevnetk 
Level: Intermediate
User Rating: Unrated
Compatibility: C, C++ (general), Microsoft Visual C++, Borland C++
Views: 1447
 
     Answer to question: How can I use the .NET HiQPdf Library from a C++ Native Windows Application? HiQPdf.com library is a powerful and precise .NET library but 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. 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:
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
//**************************************
// Name: How to call the HiQPDF HTML to PDF .NET Library from a C++ Native Windows Application
// Description:Answer to question: How can I use the .NET HiQPdf Library from a C++ Native Windows Application? 
<b>HiQPdf.com</b> library is a powerful and precise .NET library but 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. 
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:
// By: Stevnetk
//
//This code is copyrighted and has// limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=13792&lngWId=3//for details.//**************************************

//see <a href="http://www.hiqpdf.com/demo/ConvertHtmlToPdf.aspx">html to pdf </a>
#include <windows.h>
#include <iostream>
#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"http://www.google.com");
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;
}


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.