TCPDF / HTML2PDF - php

I am trying to understand what is the interest of HTML2PDF versus using directly TCPDF.
In order words, What are the benifit of HTML2PDF ? Why it's better that use directly TCPDF ?

as you know HTML2PDF (for PHP 5.x) is based on TCPDF.
HTML2PDF handles HTML better than TCPDF, and HTML2PDF can use CSS Classes, and have a couple more of cool functions, specially for dynamic content which TCPDF alone does not handle well. think of it as "TCPDF++"
Download HTML2PDF or go to their website and look at the examples, they will show you better than me!!
Don't forget to set set_time_limit() when generating large documents, to know why look # this post.

For some developers, it is faster to write a template that produces specific HTML instead of expressly making all of the necessary API calls to build the PDF one piece of text and one box at a time.
I'm personally a big fan of wkhtmltopdf, which uses the popular, powerful and standards-compliant WebKit rendering engine. Most common HTML-to-PDF programs either don't understand CSS, or understand CSS poorly.

Related

PHP PDF conversion

I am using PHP 5.0 pdf library to convert files dynamically into PDF.
I am using this reference from the official PHP website using PDF_new(), creating its object and using PDF_set_info and PDF_get_buffer functions.
This works fine, but when I want to create PDF pages and writing the content inside of it, there is no reference given anywhere on how to convert an already existing page to PDF. Say a page in my folder bill.php with CSS too needs to be converted to PDF on the fly.
Well converting HTML to PDF is not that easy, there are several libraries out there that might fit your needs. But none has full html/css capabilities, especially not css3.
FPDF
http://www.fpdf.org
TCPDF
http://www.tcpdf.org
DOMPDF
http://code.google.com/p/dompdf/ (this class allows you to easily convert simple layouted websites to pdf. i used this class quite often with almost no problems. sadly this library does not support converting of forms to usable input fields.)
WKHTMLTOPDF
http://code.google.com/p/wkhtmltopdf/ (actually a linux package but php wrappers are existing. this gives almost full html capabilities and awesome results)
html2PDF is a nice library to use. Make sure you change the default language to English though. I've used it many times to create dynamic invoices with tables and divs. Works really well.
Refer some of the articles, which may help to improve your knowledge as well as clear some of doubt of you.
Getting started
Convert HTML To PDF in PHP The Easy Way
How to Generate a PDF With PHP
Convert HTML to PDF
This HTML to PDF SDK may also help you.
Hope, it will help you.

What do you think about "TCPDF like" PHP solutions to generate a PDF?

Don't you think the TCPDF solution force you to reivent the wheel, in term of layout rendering?
I think TCPDF doesn't allow a good separation of concerns, and is just too limited when you try to render dynamic tables, or wide portions of text.
I'm pretty interested in alternative solutions like wkhtml2pdf or XSL-FOP, but I would like some experience feedback.
Thanks in advance.
I used FOP and Jasper Reports over the last years. Both are Java-Solutions but can be easily used within a PHP application. For that I use a PHP/Java-Bridge (at the moment the one from the ZendServer CE, but there is also a Open-Source-Bridge at Sourceforge)
For me JasperReports works better. There is a graphical WYSIWYG-Editor (iReport) for creating the Templates. FOP is great too but writing the XSL by hand is difficult and lengtly.
I haven't tried the two pdf generators that you mentioned, i'll give them a shoot...
I used TCPDF and it worked good for me... It allows easily to turn html code to a pdf file...
The drawbacks is that the translation is not always perfect, specially when you use css styles.
Another drawback could be the heavy weight of the library...

Generate PDF file from HTML page while on shared hosting

I have very limited access to enable extensions etc on my hosting but am looking to generate a PDF from an HTML page (with css/images) through PHP.
Any ideas how I can achieve this with next to zero CL access etc?
Preferable not a "hack" / relient on a service (as I'll be looking to use this long term).
When generating HTML to render in to the PDF, create that HTML in single $html variable. This can be used to pass to the any of the pdf rendering api's.
Widely used API's are DOM PDF, html2pdf, html2ps.
Some of the API's like html2ps also supports the external css & classes also. Some required inline CSS.
I have used DOM PDF & html2ps
here are the links
domp df
HTML2PS & HTML2PDF
A number of solutions exist out there: domPdf, mPdf, html2pdf, tcpdf, zendPDF (zend framework) etc. I have used domPdf and mPDF very extensively and others just "in passing". domPdf is very easy but doesn't quite have the bells and whistles. html2pdf is not bad either, however, I am partial to mPDF as I believe it has the best set of features out there. For full documentation see this link: http://mpdf1.com/manual/index.php
I've converted pretty complicated web pages into pdf and mPDF seems to render them the best.
Found this yesterday just here at SO: mPDF. Haven't tried it, but the documentation is solid.
Check out html2pdf, I never used it, but it looks promising.

PHP HTML to PDF free convertor Resources

What is the best PHP HTML to PDF free converter around, not just in terms of functionality but also in terms of resource usage and speed
Thanks
Have a look at open-souce fpdf library.
Check dompdf, an HTML to PDF converter written in PHP. No external dependencies, it supports complex tables, images and even external style sheets.
http://www.digitaljunkies.ca/dompdf/
If you want to be really clever about it, you could programmatically create a new Google doc containing your HTML and CSS, then programmatically export it as a PDF. No resource usage on your part, and it works very well.
Start here:
http://www.tecnick.com/public/code/cp_dpage.php?aiocp_dp=tcpdf
We recently used this on a project with quite a bit of luck. I don't know that it will go straight from HTML to PDF like you are looking for, but it is a good set of tools.

How do I replace outbound link URLs in a PDF document, using PHP

I have a PDF document with some external links.
I'd like to parse the document, replace the destination of the links then close (and serve) the PDF document, all using PHP
I know I can do this with PDFLib but I don't want to incur this cost.
I could re-write the document with FPDF or DomPDF, but some of these PDFs are quite complex so this would be a major time investment.
Surely there must be a way to do this directly to PDF docs, using native PHP?
TIA
I don't think there is a text/hyperlink changer class for PHP. The closest products, like pdftk, only does higher-level stuff like merging, splitting and applying watermarks.
Changing a pdf is much more difficult than generating it, so you need to use a pdf editor like Nitro PDF (untested), or why not Acrobat/Illustrator/InDesign.
If you must use PHP, regenerating the PDF:s with one of the free classes seems to be your best choice. I like FPDF very much, it gets my recommendation. If you decide to use it, check out FPDI as well, it can use existing PDF files as a template, maybe it will help you. Good luck!

Categories