When you need to convert HTML file no matter online or local files to PDF from VC++ code, the following article will be quite helpful for you. Here I will introduce one software named VeryDOC Doc Converter COM, which is a COM object (or DLL Library, or Command Line), enabling developers to access the converter via any programming or scripting languages, such as Visual Basic, C/C++, Delphi, ASP, PHP, C#, .NET, etc. The main function of this software is that converting files like Microsoft Word, PowerPoint, Excel, JPG, PNG, GIF, and HTML to PDF and set some limitations. Please get more related information on homepage, in the following part, let us check how to use this software from one example.
Step 1. Free trial of Doc Converter COM
- All the VeryDOC software is free downloading and trial including the COM version software. But when converting HTML to PDF by this software, please make sure you have the following application installed on your computer:
PDFcamp V1.8 or newer, or PDFcamp Pro V1.8 or newer and Windows Internet Explorer 5.0 or newer. - When downloading finishes, there will be a zip file. You need to extract it to some folder then you can find code template and DLL Library.
Step 2. Convert HTML to PDF from VC++ code.
- When you open this software folder then you can find code templates of VB, VC and others. Please run this software according to the template and usage.
- Here is one example for your reference.
How do I call DocConverter COM from VC++ code?
A: Please look at following VC++ function,
BOOL ConvertHTMLToPDF (const char *lpHTMLFile, const char* lpPDFFile)
{
IPdfCreator pdfout;
BOOL bRet = pdfout.CreateDispatch(_T("PdfOut.PdfCreator"));
if(bRet == FALSE)
{
printf("Can't locate 'PdfOut.PdfCreator' in this computer, please reinstall this product to try again.\n");
return FALSE;
}
pdfout.SetActivePrinter("PDFcamp Printer");
pdfout.SetFileName(lpPDFFile);
pdfout.SetHtml2PDF(lpHTMLFile);
pdfout.SetPaperType(0);
pdfout.CreatePDF();
while(pdfout.GetStillRunning() == 1)
{
MSG msg;
while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage (&msg);
DispatchMessage (&msg);
}
Sleep(20);
}
pdfout.DetachDispatch();
return TRUE;
}
For more information, please read the "readme.txt" file in the "doc2pdf_asp" folder.
Please note when converting HTML to PDF, you need install the MS Internet Explorer 6.0 (MS IE6.0) to convert HTML files to PDF files, the MS IE5.0 and IE5.5 are not enough. If you need to know more information, please check user manual. During the using, if you have any question, please contact us as soon as possible.