I use the pear extension File_PDF in an old PHP app I maintain.
It seems like the last version by that module is version 0.3.3 from and it is not maintained anymore and has been superseded by the package Horde_Pdf
from pear.horde.org.
Can I just change the codebase to the new package? Or do I need to change the function calls?
I started a repository where I convert the old code to the new code at https://github.com/rubo77/File_PDF
The old PDF.php
was renamed to Writer.php
and the fonts are now in another folder. and the class File_PDF
was renamed to class Horde_Pdf_Writer
.
I replaced the code in my scripts:
and changed
require_once('vendors/pear/File_PDF/PDF.php');
$this->pdf = &File_PDF::factory();
to
require_once('vendors/pear/Horde_Pdf_Writer/Writer.php');
$this->pdf = new Horde_Pdf_Writer();
now I get the error
Uncaught Error: Class 'Horde_String' not found in /var/www/app/vendors/pear/Horde_Pdf_Writer/Writer.php
A better solution would be to use a more actively maintained PDF generation library like TCPDF, which doesn't need much changes either, e.g. from file_PDF to TCPDF just:
newLine()
with Ln()
getOutput()
with Output()
SetFont('Arial', ...
doesn't work, so just use SetFont('', ...
If you really need this old Library you need to also download those packages:
To let it run in a local folder, edit some files:
instead of calling File_PDF with
require_once('vendors/pear/File_PDF/PDF.php');
$this->pdf = &File_PDF::factory();
now call
require_once('vendors/pear/Horde/Pdf/Writer.php');
require_once('vendors/pear/Horde/Pdf/Exception.php');
require_once('vendors/pear/Horde/String.php');
$this->pdf = new Horde_Pdf_Writer();
in Writer.php
the function _getFontFile()
needs these extra lines:
$fontname = Horde_String::ucfirst(Horde_String::lower($fontkey));
require_once('vendors/pear/Horde/Pdf/Font/'.$fontname.'.php');
$fontClass = 'Horde_Pdf_Font_' . $fontname;
in Exception.php
you need to call
require_once('vendors/pear/Horde/Exception/Wrapped.php');
in Wrapped.php
you need
require_once('vendors/pear/Horde/Exception.php');