在 PHP 8 上运行 File_PDF(升级到 Horde_Pdf)。

huangapple go评论69阅读模式
英文:

run File_PDF on php 8 (upgrade to 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();

现在我收到以下错误:

未捕获的错误:在/var/www/app/vendors/pear/Horde_Pdf_Writer/Writer.php中找不到类'Horde_String'
英文:

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

答案1

得分: 0

更好的解决方案是使用一个更活跃维护的PDF生成库,比如TCPDF,它也不需要太多的更改,例如从file_PDFTCPDF只需:

  • newLine()替换为Ln()
  • getOutput()替换为Output()
  • 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');
英文:

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:

  • replace newLine() with Ln()
  • replace 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:

  • Horde_Exception
  • Horde_Util
  • Horde_Translation

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

huangapple
  • 本文由 发表于 2023年1月9日 17:51:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/75055544.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定