WYSIWYG editor and PDF creation

I’m an inexperienced PHP developer, so I am looking to start a new personal project to get some practice in. I need the app to give the users a WYSIWYG editor (mostly ajax drag and drop rather than custom html code) and send the output via email as a PDF attachment.

I’m guessing theres some good modules/APIs out there which will allow me to do this. Can anyone suggest some?

WYSIWYG might not be too terribly difficult, but I’ll warn you right now that PDF generation is usually a path that’s not very fun to walk down. There are a couple of free libraries, and a couple paid ones, and unless things have changed since I last researched them, nearly all of them are rather subpar.

Why is PDF no fun?

PDF has no free flow elements, so text will run off the page and now wrap, no support for tables and not layout options to align images.

However there are better solutions to use outside of a library.

Latex
Its a darn old thing, but it works. If you want something to just work without being so picky on the layout it generates. You can convert latex to HTML and PDF. It handles table of contents very well and most publications in universities are written in latex and converted to PDF.

OpenOffice
You can generate a HTML document and open it in Open office and convert to PDF / MS Doc / Etc. Running it means you need java and open office (duh). You’ll have to run open office in headless state (non gui) with socket / port support. You can use http://www.artofsolving.com/opensource/jodconverter to talk to the port and convert document.

If you want to use open office, there is a nice project called jodconverter, which you might want to look at.

I will not be generating pageless web pages as pdf. The editor will allow the user to modify the layout with page boundries (A4, Letter size etc) and then I want to generate PDFs from it. Does it sound feasible?

Not sure how I would approach such a thing yet!

FPDF is a good free PHP Library which is used to generate PDF files. I’ve used it several times now. There’s also pdflib as well but that’s paid for and quite frankly I preferred the way fpdf worked.

I’ve often used PHPMailer (an php emailing library) and FPDF to send emails with PDF attachments.

For WYSIWYG Editors I’ve used TinyMCE before but fckeditor was also another decent one that I’ve heard good things about too. Very customizable too.

Generating PDF’s is a LOT of work.

The problem with existing libraries is they are limited in what they do. PDF is a vector based format and almost every object you see is sequence of GD instructions. So if you want a table, you actually have to draw the borders, from top-left to bottom left, to bottom right, to top right and back to top left to complete the border. Drawing cells is done in a similar manner.

Some libraries might offer basic table rendering, but most suffer from overflow issues, etc. Nested table rendering is something very difficult to implement correctly so don’t expect any of the PHP libraries to render properly if you nest a table inside another.

Cheers,
Alex

This. PDF Generation in PHP isn’t fun because it’s fundamentally different to how you would normally use PHP.

Try out: Dompdf , if you want the straight forward approach in converting the HTML -> PDF.

Thanks

Hi Kyberfabrikken, sutabi,

I looked that up and it does seem promising. What I wonder about though: is OpenOffice/JODConverter “smart” enough to do sensible overflowing etc? I’ve used FPDF, TCPDF, DomPdf, LaTeX, but they all suffer from the same issue: once you start working with dynamic stuff, the overflow doesn’t really work correctly, and you get pages that are formatted in a very weird way. I want to try JODConverter, but I was wondering if it had the same issue?

I would make wysiwyg editor for XSL-FO rather than pdf, and use Apace fop to convert it to PDF. XSL-FO supports tables and has many other useful features. And it’s xml based, so it’s pretty easy to modify/generate with php.
http://www.w3schools.com/xslfo/default.asp

Apache FOP http://xmlgraphics.apache.org/fop/index.html
really easy to use and install.

Thanks all! XSL-FO looks interesting too!

I’ve used FPDF and I liked it. It’s kind of a hassle to get things how you want though.

Not a human readable format for the most part. TCPDF will parse simple html which can be used in conjunction with the WSYWIG editor. Don’t expect much though.

My own little experience with libraries like FPDF is that it works reasonable well if you want to generate basic PDFs. So mostly text. Maybe a heading and page break here and there. As soon as you want to do more, it gets complicated and messy.