I have not had success with the PDF generation engines currently supported by this module, so I have integrated the very nice tool wkhtmltopdf (http://code.google.com/p/wkhtmltopdf/), which uses qtwebkit to generate PDFs. This produces very nice results, which look essentially like what you get when you "Save as PDF" (or "Print to File" > "PDF") from a browser.

There are some setup/installation requirements for getting this to work. You may be able to use the statically linked version of wkhtmltopdf, or you may have to compile it (as I did on a 64-bit machine). Since qtwebkit also needs an X server, you may also need to use Xvfb, the "fake" X server commonly used for server-based applications that need X support. I have included, in this patch, support for the use of Xvfb. See the file wkhtmltopdf_config.inc.php and bin/README.txt (where you must put the binaries for wkhtmltopdf, and perhaps Xvfb) for details. Trust me, though -- the extra work is worth it. It makes a lot of sense to use the same libraries that a browser uses to generate PDFs, than to rely on something like dompdf trying to replicate everything a browser does.

I am successfully using this on a Drupal 5 based site. The attached patch is based on the latest from CVS HEAD, however, and has not been tested as such. I simply integrated the changes I made into a copy of CVS HEAD and produced a diff. Please let me know if more information is needed to get this working.

Thank you for providing this module!

CommentFileSizeAuthor
print-wkhtmltopdf.patch11.7 KBnoelbush
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

rsvelko’s picture

Great!
Reviewed the patch and everything is simple to understand and seems ok.

Could not test cause I lack time and heard that maintainer of this modue is going to test and commit soon.

One last question - is this pdf export tool really so great - I constantly read so - and hope so.

rsvelko’s picture

Is somebody rerolling the patch for 6.x? If not I will for sure.

ezeey’s picture

Unfortunately I don't have enough skills to port it to 6.x but I would definitely use it ;-)
Do I need my own server to use wkhtmltopdf or could I also run it on shared hosting?

jcnventura’s picture

Status: Needs review » Postponed (maintainer needs more info)

Hello, noelbush.

First, thanks for the contribution.

A couple of points:

1. Your pclose doesn't use the same variable as the popen, so by now your machine must have several instances of Xvfb running in the background.
2. Why are you launching the wkhtmltopdf twice?
3. The 300 dpi setting is really small, 96 dpi would be a lot better.
4. Why are you setting the Xvfb fonts explicitly? I think that's a task for the Xvfb installation and configuration..
5. Launching at 1024x768 is really a waste of memory.. 320x200 should be sufficient and it saves around 3Mb.

In light of the above, I find it really hard to believe that you have THIS code running on a Drupal 5 server..

However, you did 99.999% of the work, and I have used your code to develop a patch for Drupal 6 which I have successfully used, and IT WORKS GREAT. I have chosen to simplify it a lot, as all the trouble you went to to recreate a dompdf-like interface is really unnecessary and it only adds overhead in class creation and file inclusion.. I have reduced all of it to a 60-line PHP function.

I will commit that patch today, but there's a couple of things I want to try to do before an official (.6) release:

1. I don't like the use of temporary files for logging.. There's a place for this information: the Drupal log.
2. I also don't like the random display number.. The probability that the same number will be generated is too high when you have a site which permits several users to generate PDFs. I am thinking of a PDF generation of invoices on a e-commerce site, which could easily create problems.

João

rsvelko’s picture

João, it is always better if you share the code - so we can help with 1 and 2.

jcnventura’s picture

Status: Postponed (maintainer needs more info) » Active

Just committed everything.. And I am not really expecting help. That's just a TODO list to remind myself not to put this as fixed yet..

João

jcnventura’s picture

There is still some minor things to do (like documenting the installation), but in general, the wkhtmltopdf implementation is complete.

Please test it. You'll have to place symbolic links (or the binaries themselves) to the wkhtmltopdf and Xvfb somewhere inside the module directory. I wasn't able to make it use an X server running on the same machine as the Apache/PHP server, so I guess 99.9% of us out there will use Xvfb.

João

jcnventura’s picture

Status: Active » Fixed

No more annoying blocking from the processes.. This is now usable.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Wassim Ghannoum’s picture

how to install Xvfb on a windows machine ?

ppant’s picture

Category: feature » task

Hi
How can I reduce the size of generated PDF and how to provide font name and size. I am using it in CentOS 4.

faisalnet5’s picture

Version: 5.x-4.x-dev » 6.x-1.x-dev
Component: Code » Documentation
Assigned: Unassigned » faisalnet5
Category: task » support
Priority: Normal » Critical
Status: Closed (fixed) » Active

Is there any good manuals/documentations for "wkhtmltopdf" How to use with Drupal-6? Specially "Xvfb" server part is really confusing because there is no good download source for windows user. Where to put "wkhtmltopdf" and "Xvfb" and how to run the X-Server for the first time? How to setup the whole things with drupal-6 so that it will work just like pdf creator like "tcpdf".

Let's see, if i do find some ways out then for sure i will make one manual for others. But any help will be really appreciated.

Regards

EugenMayer’s picture

Priority: Critical » Normal

@12: actually istalling and using wkhtmltopdf is plain-easy. Download the compiled versoin, install the x11libs, make wkhtmltopdf executable and place it in the lib forlder. your done. No need to configure anything else. this is not critical at all btw.

jcnventura’s picture

Status: Active » Closed (fixed)

Don't reopen issues, please.

ukrdrupal’s picture

EugenMayer, but how to get the static wkhtmltopdf to work on cPanel shared hosting running CentOS 4, with no libX11 installed?

I made a post here, that I hope you can take a moment to read: http://drupal.org/node/604992#comment-3473720

If you can help with this, that would be amazing. ...Not critical depends on your site and your view of what is critical to the success of your site. I consider wkhtmltopdf critical for my users.

(As I state in my other comment, I am using wkhtmltopdf on a Dedicated Server that I run, where I have the libX11 installed. The problem really is in a shared hosting environment with cPanel. However, I think there may be a solution to get it running and I am wondering how feasible it is. I have the details in my other comment.)