For a recent project, I recreated an online version of the Federal form Request for Taxpayer Identification Number and Certification, otherwise known as the W-9. The form was stylesheet formatted and implemented as a Drupal custom node type. Then came the project requirement to convert the filled out form into a PDF document to be emailed as an attachment. Uh oh.
Using the contributed module pdfview, I quickly found that the underlying PHP class TCPDF does not handle CSS layout. No divs, no floats, only tables. Swell. Specifically, TCPDF supports the following elements:
h1, h2, h3, h4, h5, h6, b, u, i, a, img, p, br, strong, em, font, blockquote, li, ul, ol, hr, td, th, tr, table, sup, sub, small
I do a little more research to discover that dompdf is highly regarded for its HTML layout rendering and will read external stylesheets. I fire it up, but it too lacks support for div positioning and floats. Looks like my form layout has to go at this point.
Not to worry, I'll just find a utility that converts PDF to HTML. Surely Adobe Acrobat 8 Professional is up for the job. I export the original government-issued PDF to HTML 3.2. To say the results were less than desirable is an understatement. I'll grant that the W-9 is about as complex a form as you might come across. The problem was not just that the document layout was not preserved, but all the information was not captured in the conversion either. A big thumbs down to Acrobat on this task.
Scrambling now, I remember that Google provides HTML previews of PDF files in its search results. While the output was clearly superior to what Acrobat accomplished, it uses absolute positioned divs which is a non-starter for either TCPDF or dompdf. Incidentally, based on the identical output of pdftohtml, I'm guessing Google is using an Xpdf package to generate the HTML.
So I have set the Way Back Machine to 1995 and am now hand converting my stylesheet form layout to tables. If you've read this far looking for a solution to converting HTML forms, the best advice I can give you is to plan ahead when dealing with PDF conversion and leave the HTML 4 specifications behind. Anyone recall how to do table borders again?








Follow up
Just a quick follow up to this post... after massaging the layout to use tables, I ended up swapping out the TCPDF lib for dompdf and the conversion results were much better. Perhaps I'll write up a separate blog entry comparing the libs.
Found your post, wish it was sooner...
I've come to the same conclusion myself, domPDF was much better than TCPDF at the conversion. The only issue I've run into (and I'm early in my research) is getting the title of the pdf (or what appears in the title bar) to output correctly.
I've also noticed that the styles attached to the cck field elements don't seem to be properly processed, so I'm looking for a solution to that as well.
Currently it says '271' which is the nid of the node I am converting, and obviously I want it to be $node->title.
Any advice?
Dave
php form to PDF using dompdf
I'm in the process of converting a form in php to pdf using dompdf, however, I cannot, for the life of me, figure out how to get it done.
Any help would be wonderful (I contacted the guys who created dompdf, but have not hear back).
Mark
TCPDF / DOMPDF
I use Drupal and wrote a custom module that uses TCPDF to generate a PDF file (looks like a 'form' without really being a 'form').
My user wants to be able to 'fill out the form'. I'll dig more into TCPDF but I don't remember anything 'form' specific when defining fields. Anyone know if this is do-able in TCPDF or DOMPDF?
Converting PDFS with Dompdf
Hi,
I have converted my php webpage to a pdf using the Dompdf.
The only problem is it doesnot pick up the table tags(i.e the trs ,the tds!!) and the form tags(specially text boxes and text areas).
Can you tell me the reason behind, so Can you suggest what Do I need to do so that it picks up these tags as well.
Thanks in advance.
IMG Tag not working with Dompdf
Hi,
I am trying to convert a html page to a pdf document.
The dompdf has coverted everything on the html page to pdf , except the images on the page. The img tag on the page, is somehow, not picked up when the page is converted.
Can you please help me in this.
Thanks.
Post new comment