3

As part of my application, my client has requested that I include an automated e-mailing system. As part of this system, I generate HTML code and use automation to send it via. Outlook.

However, they also require a PDF copy of the HTML document to be sent as an attachment. My initial attempts involved using libHaru, which proved difficult to use efficiently, as I was required to create the PDF document from scratch, which required computation of the position of each of the lines in a table, and positioning of all the text, etc.

I was wondering if there would be a way to programmatically convert HTML code (or an HTML file if need be) into a PDF document either by using Win32/MFC itself or an external library.

Thanks in advance!

EDIT: Just to clarify, I am looking for solutions which minimize external dependencies.

Thomas Russell
  • 5,870
  • 4
  • 33
  • 68

4 Answers4

1

You should evaluate this utility wkhtmltopdf: http://code.google.com/p/wkhtmltopdf/

You can call it from the command line without the need to run a setup.

I use it generating my output documents as html then cal a ShellExecute(...) to convert it to PDF. It's great!

Inside uses webkit + qt. So compability with modern HTML is OK.

Hope it helps.

Albertino80
  • 1,063
  • 7
  • 21
  • Nice solution, this is a lightweight solution which I can remotely download and install on my clients machine via. my own application. Thanks! – Thomas Russell Aug 25 '12 at 19:46
0

I'd take a look at PDF Creator, which can be used as a COM object (that acts pretty much like a printer). I haven't used it to print HTML, so I'm not sure, but my guess is that you'll probably end up having to instantiate a web browser control to render the HTML, and then feed it from there to the PDF control.

Jerry Coffin
  • 476,176
  • 80
  • 629
  • 1,111
  • As far as I know, this can't be embedded in the application, so it becomes an external dependency, so I'm looking for solutions which minimize external dependencies, I'll update the question to clarify. Thanks though! – Thomas Russell Aug 24 '12 at 19:11
0

Some possible answers are in this thread:

C++ Library to Convert HTML to PDF?

Not sure if they will satisfy your particular requirements, but these might at least get you started.

Edit:

Some other possible options here.

Community
  • 1
  • 1
mwigdahl
  • 16,268
  • 7
  • 50
  • 64
0

Not MFC but you can try QtWebKit. It can render and export HTML to PDF, PNG, JPEG

Viet
  • 17,944
  • 33
  • 103
  • 135