I’ve been using the FPDF PDF generator library for years now as the de facto method for my PHP projects to produce PDF reports. However, one minor annoyance is that the generated PDF files often falter when it comes to the inclusion of certain special characters – like the degree symbol (°) as an example. (Basically, something like °C becomes °C in the final document)
The reason for this happening is that Arial, the default used/included font, is of type ISO-8859-1 while the degree symbol is UTF-8 encoded. So in order for us to include special symbols or characters from other languages, we need to either try and convert them into our font compatible ISO-8859-1 format, or perhaps switch to using a different TrueType or Type1 font (which then would contain the desired character set).
Now while UTF-8 support is available via a modified class, the easiest way to fix the degree symbol issue without having doing any real work is to simply make use of the PHP utf8_decode function, which convert UTF-8 encoded strings to their ISO-8859-1 equivalents.
In other words outputting utf8_decode(“°C”) to your PDF should result in the expected °C
I have mentioned the useful FPDF PHP PDF generating library before, but today I’m quickly going to point out how you can solve the problem of inserting extra long lines of text into a table and forcing the table to automatically wrap or linebreak all of your text without simply chopping it off at the end when it reaches the right hand border of the cell.
The solution to this is pretty simple and it involves dropping the use of the Cell() function and instead incorporating the MultiCell() call.
The MultiCell basically allows for the printing of text with line breaks. These line breaks can be automatic, in other words when the text hits the right border of the cell, or explicit, i.e. via the n control character.
The function cleverly automatically lays down as many cells as possible, one below the other and all without any input or direction from you. The cell block can then be frames and even have its background painted if you want.
Parameters are pretty self-explanatory. You can set the width of the cells, the height of the cells, the text to print, whether or not you want a border, how you want the text aligned and whether or not you want the background filled.
Putting this in code, you would get a call that looks something like this:
$pdf->MultiCell(275,7,’Insert your long string here’,1,’L’,false);
Nifty.
Related Link: http://www.fpdf.org/en/doc/multicell.htm
Foxit Reader 1.1 is an incredible little PDF viewer that features some powerful tools while remaining pretty damn quick. It’s free for non-commercial usage and features most of the viewing tools you’ve come to expect from the big daddy of PDF readers, namely Adobe Acrobat. Among these tools included in Foxit is the standard zoom functionality, full document navigation, bookmarks, thumbnails, text selection, snapshot image grabbing as well as the old faithful, full screen document viewing.
The download .deb package weighs in at a handy 3.6 MB and when running, has a claimed memory consumption that remains less than 15 MB. It launches instantly when called and can load a PDF document in under 3 seconds.
And installing it in Ubuntu is an absolute breeze.
First, download the .deb package of Foxit’s official download page at http://www.foxitsoftware.com/pdf/desklinux/download.html. Once it is downloaded to the appropriate folder on your system, install it using the dpkg Debian package manager. To do this run a terminal in administrator mode and call:
sudo dpkg -i FoxitReader_1.1.0_i386.deb
And that’s it really. Foxit will be installed on your system and you’ll see the menu shortcut being added under the Office tab on the Applications main menu. It is also added as a right-click context menu selection for PDF files. Couldn’t be simpler and works like an absolute charm! :)
(Oh, and finally, for the future when you might find something even better, you can uninstall it in the usual way using: dpkg -r FoxitReader)
Saving a web page to a PDF file for later offline viewing has just become a whole lot simpler thanks to the excellent pdfmyurl.com web service that aims to convert any URL you feed it into a downloadable PDF file. The application is particularly easy to use, looks good and returns some excellent results, making it the perfect tool for a beginner web user.
However, its magic doesn’t quite just end there.
Equipped with a host of settable options like layout, page size, dpi and zoom factor for example, pdfmyurl is geared towards allowing other developers to use the service either by making calls to it via an href anchor with the associated GET variables set, or even on their own servers if for instance they wanted to make use of the brilliant wgets functionality in order to rip a website down into PDF format.
would result in the system generating a pdf file entitled opentracker.pdf in a landscape orientation and with a custom header text.
Particularly interesting for this system is the way it manages to keep menus and links active in the generated PDF file, meaning that should the page you saved as a PDF reference another article, you could still access that referenced article at a later stage by clicking on the link contained in the PDF file.
In other words, this whole damn system is simply put, pretty nifty! ;)