views:

300

answers:

4

Do you know if Perl's PDF::API2 module can generate documents with both English and Hebrew text? I have searched for a while and cannot seem to find how to handle right-to-left language text.

Eventually I will want to list English in one column and Hebrew in the other. But I would be happy to have the two texts on different lines for a start.

I am open to using an external tool if I have to, but am hoping for a more lightweight approach than using OpenOffice or FireFox to print to PDF.

+1  A: 

Well, I do not know how to use PDF::API2, let alone create Hebrew documents using it, so I cannot help you there.

I would first try PDF::FromHTML before diving into PDF::API2, but then, I am easily scared.

Sinan Ünür
If you are easily scared, do *not* look at the PDF::FromHTML source.
ysth
Yes, but using the module was not a scary experience.
Sinan Ünür
PDF::FromHTML won't work because Hebrew text flows left-to-right, not right-to-left. And this is done in HTML via CSS and PDF::FromHTML doesn't do CSS.
mpeters
+1  A: 

I don't use Perl and so cannot answer your question about PDF:API2. But I do use Java and know that the iText library supports right to left text - iText is available for .NET too.

Here's an example of changing text direction: http://itextdocs.lowagie.com/examples/com/lowagie/examples/fonts/styles/RightToLeft.java

Steve Claridge
A: 

Do you really have to use PDF::API2? I didn't know that library but just tried it out; it seems to have a great base code for low-level programming, but I didn't see anything relating to actual typography, let alone for the particular demands of right-to-left typesetting. The Hello, World! example works great, and you can even replace the core font that is used there by an arbitrary TrueType font (just replace the $pdf->corefont('Helvetica-Bold'); call with $pdf->ttfont('/path/to/font/file.ttf');) But I couldn't find anything about encodings, to start with, so I couldn't even set a single Hebrew character because the UTF-8 sequence came out garbled in the PDF file (I also tried a few other encodings, to no avail). Obviously there is some support for it since I see a file called PDF/API2/Basic/TTF/Cmap.pm (cmap being the TrueType table that defines the encodings of the font), but, again, it seems to be at rather low level.

Should I add that documentation seems extremely scarce (including a completely empty section entitled “Fonts and Typesetting”!), and that development has apparently halted in 2005; I would deem that the library is, as yet, too incomplete to be used for true projects (especially such ones as yours). It's a real pity, as there seems to have been so much development on it ten years ago.

Arthur Reutenauer
A: 

PDF::API2 has a lot of functionality, but it's extremely esoteric. I've found the documentation to be very difficult to mine for the information needed. You must get everything "just right" in order for the PDF to be rendered properly, and as if your requirements change, it tends to have a cascade effect on your existing code to get everything to play together well. For example, inserting one element at a particular location may mean that you need to re-calculate the positions of all the other elements rendered on that page, down to single-point precision, depending on how you're using the API.

As a result, we fairly recently abandoned a solution that had been using PDF::API2 and instead started generating HTML instead, which we then converted to PDF using an external tool. There are some good free ones, for example PDF::FromHTML as suggested by Sinan Ünür. There are also some more feature-rich commercial ones if you want to get fancy with your HTML and have it translate nicely into PDF (although I haven't used them personally).

If you need to do some simple manipulation on existing PDF's, rather than generating them, I would use (and do use) CAM::PDF.

In short, I don't recommend PDF::API2, unless you're willing to spend a large amount of time figuring out all of its intricacies and personally supporting your app well into the future. It's extremely powerful and feature-rich, but unless you know exactly what you're doing, the lack of documentation and examples will hinder you more than the module helps.

Adam Bellaire