运行File_PDF在php 8(升级到Horde_Pdf)



我在一个旧的PHP应用程序中使用了pear扩展名File_PDF。

似乎该模块的最后一个版本是来自0.3.3的版本,它不再被维护,并已被来自pear.horde.org的软件包Horde_Pdf所取代。

我可以将代码库更改为新包吗?或者我需要改变函数调用吗?

我创建了一个存储库,在那里我将旧代码转换为新代码https://github.com/rubo77/File_PDF

旧的PDF.php被重命名为Writer.php,字体现在在另一个文件夹中。class File_PDF重命名为class Horde_Pdf_Writer

我替换了脚本中的代码:

和改变

require_once('vendors/pear/File_PDF/PDF.php');
$this->pdf = &File_PDF::factory();

require_once('vendors/pear/Horde_Pdf_Writer/Writer.php');
$this->pdf = new Horde_Pdf_Writer();

现在我得到了错误

Uncaught Error: Class 'Horde_String' not found in /var/www/app/vendors/pear/Horde_Pdf_Writer/Writer.php

一个更好的解决方案是使用一个更积极维护的PDF生成库,如TCPDF,这也不需要太多的更改,例如,从file_PDF到TCPDF只需:

  • Ln()代替newLine()
  • Output()代替getOutput()
  • SetFont('Arial', ...不工作,所以只使用SetFont('', ...

如果你真的需要这个旧的库,你还需要下载这些包:

  • Horde_Exception
  • Horde_Util
  • Horde_Translation

要让它在本地文件夹中运行,请编辑一些文件:

代替用

调用File_PDF
require_once('vendors/pear/File_PDF/PDF.php');
$this->pdf = &File_PDF::factory();

现在所称的

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();

Writer.php中的_getFontFile()函数需要这些额外的行:

$fontname = Horde_String::ucfirst(Horde_String::lower($fontkey));
require_once('vendors/pear/Horde/Pdf/Font/'.$fontname.'.php');
$fontClass = 'Horde_Pdf_Font_' . $fontname;

Exception.php你需要调用

require_once('vendors/pear/Horde/Exception/Wrapped.php');

Wrapped.php你需要

require_once('vendors/pear/Horde/Exception.php');

最新更新