How to make a pdf file using PHP - php

How can I make a PDF file in PHP. What I want to make is a student list. So I want to query the database, get the information and give it to the user as a PDF when he clicks generate student list.

You have two good options first is the standard php library for manipulating pdf's: http://us2.php.net/pdf
Or you can use http://www.fpdf.org/. I would recommend the second.
Other options include:
www.pdflib.com

PEAR has the PEAR::File_PDF package.

There are are already many libraries available with PHP bindings. One that comes to mind is PDFLib (www.pdflib.com). If I am not mistaken there should even be a lite version that you can use for free. But just check it out.
Hope it helps

I use the ezPDF class. Lightweight, simple, easy to use, and handles most cases.

FPDF is a classical in the field. It seems it has limitations when handling Unicode (eg. Asian char sets), so there are libraries extending it (UFPDF, TCPDF...).

Related

Localization file for JS and PHP

I did some search about localization files, see that we can use .po file or gettext but, is there any tutorial or sample of a unique solution that will work both in javascript and in php.
I want to only maintain one localization file per language that will work with both JS and PHP languages.
Would appreciates if someone can point me to some links or samples...
I found that it is typically a sign of a questionable design when translatable text is coded inside JS functions. JS is meant to implement logic, not content. The content should be provided by PHP (typically by using a templating engine) and should be used by JS. That way you only need a localization solution for PHP.
If (exceptions always occur) you really need to translate a phrase inside a JS routine you use an ajax call to fetch the translation. This also simplifies the access to the dictionary holding the translation tokens since it is again done by PHP. The dictionary can be kept in a single place.
Yep, there is. I've successfully used gettext.js a while ago, which is operating on .json or .po files. This way, you only have to maintain one translation source. The webpage I've used this for is located here so you can check out how I've did it. Good luck!
First, try to avoid gettext if you can. It's popular and stable, but it puts some burden on the translations maintenance: you will need to change the source strings, and when this happens, gettext needs to update all the message keys, and this may mess up the existing translations. An approach with constant message keys is much easier to maintain in the long run - you will need to remember to delete the keys you don't use any more, but it's a very small burden.
You can use the same translations storage format for PHP and JavaScript. If you use a key-based approach, as I suggest, it will probably be some JSON-based format. JSON is easily accessible in both PHP and JavaScript.
There are several ready-made JavaScript libraries for JSON-based internationalization. I happen to be a developer of one such library: https://github.com/wikimedia/jquery.i18n . It should be reasonably easy to adapt it to PHP.

Easiest way to create a table with Zend_Pdf

What's the easyiest way to create a table with Zend_Pdf?
Until now, i realized tables with horizontal and vertical lines. Is there no other solution for tables?
Thank you.
There's this project in SF: http://zendpdftable.sourceforge.net/
However it's still not very practical, compared to other libraries.
I've also found a Zend_Pdf_Helper gitHub project that maybe can help someone.
From what i have read there is no easy way to do this. The closest you will get is by using the shape drawing primitives in the Zend_Pdf API or (probably better) by switching to another PDF library entirely.
XSL:FO combined with FOP handles tables very nicely. The downside is that it is an external too, seems to be slightly dated, and documentation for it is not the greatest. This posting of mine might help: http://grover.open2space.com/content/creating-pdf-code-fop

Wrapping a text using php, based on language

My problem is that I have quite a small area (div or span), in which one to about five words are displayed. However, the area is too small for some words (for instance "muziekgeschiedenis" will surpass the area's bounds). Is there a way in PHP to wrap this word, but not solely based on number of characters? I can use wordwrap(), or just CSS properties for wordwrapping, but that may wrap this word into "muziekgeschiedeni-s", which is not wanted. It should break into for instance "muziekgeschiede-nis", based on syllables. Are there any PHP extensions that support word breaking/wrapping like this?
Thanks!
this is called "hyphenation" and this is the first link that google gives on "php hyphenation"
http://yellowgreen.de/phphyphenator
hope this helps
Here is a PHP based hyphenation library, and a port of this library to a WordPress plugin: wp-Typography.
For PHP there is this PEAR Package TexHyphen, which uses the Tex algorithm to find syllables. It is alpha for six years and not maintained though, so user187291's suggestion is probably a better bet.
An alternative to PHP would be Javascript. There is a Hyphenator lib at Google Code. Keep in mind that this approach requires the user to have JavaScript enabled though. Actually, phpHyphenator is a port of this lib.
There is also this port of the TeX-Hyphenation Algorithm.

Does a PHP library exist to work with PRC/.mobi files?

I'm writing a WordPress plugin to create an eBook from a selected category in most major eBook formats. I would like to support MobiPocket since that's the format used by the Kindle but I'm not sure how to go about it. From what I've read .mobi files are actually Palm Resource Databases (PRC) but I haven't been able to find a PHP class to work with these.
I thought about using exec along with KindleGen but that would be undesirable as it would complicate initial setup. I've also thought about hosting a web service somewhere and using XML-RPC to accomplish this but that also complicates things.
My question is: is there a PHP class/library (PHP-only preferred) that can work with PRC or even better, a class that specialises in creating MobiPocket ebooks? (needs to be open source since I'm releasing under the GPL)
I've tried searching but haven't been able to find anything.
I don't know whether you're still looking for this PHP library, but just in case: https://github.com/raiju/phpMobi. This is a library that creates mobi files from html files.
It's should still be seen as an experimental version, but it should work without a problem for basic document with a few images.
Unfortunately not; however, the binary compiled format is an open specification available at:
http://www.mobipocket.com/dev/article.asp?BaseFolder=prcgen
The only direct way of transforming the uncompiled format is using the native XML functionality of PHP to create them and then invoking a compiler with exec, which I understand you don't want to do. If you go with this route, the link above also has details about this XML format.
You might want to try the mobiperl tools,
https://dev.mobileread.com/trac/mobiperl/wiki
Please note I haven't tested them yet. But they have been
around since at least 2007 so they should work well by now.
google "Mobiperl - Perl tools for handling MobiPocket files" to
find a thread on mobileread board discussing it. As a new
poster I can't put 2 hyperlinks into my reply.
Another tool I have recently found (but not yet tested), is: http://www.phpclasses.org/package/8173-PHP-Generate-Kindle-ebook-file-in-mobi-format.html#files
It is based upon KindleGen, and looks pretty straight forward to implement.

Free reporting library for PHP without installation?

Is there a good (and hopefully free?) source library to use for PHP for creating and displaying reports? I would love one that would allow the user to view it in a nice format for saving and printing (like PDF?).
Also I would prefer one that is just files, not one that needs to be installed on the server itself as some of the people I create sites for are on shared server hosts.
Don't know if you would call this reporting but I have found these gems over the years:
http://pchart.sourceforge.net/
http://devzone.zend.com/article/4044-Dynamically-Generating-PDF-Files-with-PHP-and-Haru-
http://phppowerpoint.codeplex.com/
http://phpexcel.codeplex.com/
http://sourceforge.net/projects/phprtf/
http://www.phpconcept.net/pclzip/index.en.php
http://www.maani.us/charts4/
http://sourceforge.net/projects/tcpdf/
http://code.google.com/p/ofcgwt/w/list
http://sourceforge.net/projects/phpreports/ <-- Just found this
Here is a pdf generating library for PHP http://www.fpdf.org/ .
I have looked at a few in the past, here is 2 that I recall (and was able to search for quick):
http://www.hkvstore.com/phpreportmaker/
http://sourceforge.net/projects/repgen/
PHP Reportmaker is pretty good. Not sure if it fits the bill of what you want tho.
Examples are here:
http://www.hkvstore.com/phpreportmaker/features.asp
FPDF combined with PHPMyGraph for creating bars etc.:
http://phpmygraph.abisvmm.nl/

Categories