1

I want to use pdflib for php 8.2 in Alma 9 or Ubuntu 22.04. There is no pecl binary available. I downloaded php_pdflib.so and added it in php.ini. The required functions are available now. But PDF_new() or pdf_new() is not available. I tried to compile code from https://pecl.php.net/get/pdflib-4.1.4.tgz and https://github.com/Distrotech/PDFlib-Lite. But I faced the following error:

...
/var/tmp/pdflib/pdf.c:144:19: note: to match this _(_
  144 |     _pdf_exception(PDF_get_errnum(pdf), PDF_get_apiname(pdf), \
      |                   ^
/var/tmp/pdflib/pdf.c:925:7: note: in expansion of macro _pdf_catch_
  925 |     } pdf_catch;
      |       ^~~~~~~~~
/var/tmp/pdflib/pdf.c: In function _zim_PDFlibException_get_errmsg_:
/var/tmp/pdflib/pdf.c:929:1: error: expected declaration or statement at end of input
  929 | } /* }}} */
      | ^
/var/tmp/pdflib/pdf.c: In function _zim_PDFlibException_get_apiname_:
/var/tmp/pdflib/pdf.c:929:1: error: expected declaration or statement at end of input
make: *** [Makefile:210: pdf.lo] Error 1
ERROR: `make' failed

I know I can use other library but huge code is written in pdflib and those codes are running in php 5.4. I need to upgrade php. I followed this but same error.

Any help will be appreciated.

srvnk
  • 13
  • 3

1 Answers1

1

PHP 8.2 (released December 2022) is only support with PDFlib 10.0.1. With PDFlib 10 the deprecated functional PHP wrapper has been removed. (Marked as deprecated with PDFlib 8, released 2009). From the PDFlib 10 Migration Guide: PDFlib 10 Migration Guide, chapter 4.6 PHP language Binding

This sounds like a big effort at first, but usually the conversion of the deprecated functional PHP wrapper to the PDFlib OOP wrapper can be done with relatively simple search and replace.

PDF_begin_document($p, "", ""); 

becomes

$p->begin_document("", ""); 

i.e. PDF_ is replaced by $p-> (as the PDFlib object) and the first parameter (the PDFlib handle) is omitted. Yes, each call must be customized, but this is in general straightforward.

If you still have very old code, however, other deprecated functions may be affected. Therefore I ask you to read the PDFlib 10 Migration Guide which is included in the PDFlib 10 packages and also linked on the PDFlib Web site. If you are trying to upgrade from an older PDFlib version, I would recommend the path recommended in the PDFlib 10 Migration Guide: https://www.pdflib.com/products/pdflib-family/deprecated-api-methods-and-options/

If you are trying to upgrade from an older PDFlib version, I would recommend the path recommended in the PDFlib 10 Migration Guide:

  • first get PDFlib 9.4.0 running on your development system (this requires PHP 7.4-8.1).
  • then you can also enable PDFlib logging or PHP warnings to find deprecated code, as in the PDFlib 10 Migration Guide.
  • If you have your code free of warnings you can migrate PDFlib 10.0.1 and thus also to PHP 8.2.

This step may also have the advantage of making your code PHP 8 Ready and PDFlib 10 Ready step by step.

PDFlib 7 Lite, was released in 2011 and has already reached end-of-product lifetime 10 years ago and is no longer supported by PDFlib GmbH. Apart from that, you should also be aware of the PDFlib Lite license terms, which only allow very limited productive use. https://github.com/Distrotech/PDFlib-Lite/blob/master/doc/pdflib/PDFlib-Lite-license.pdf

Therefore I would recommend that you use the PDFlib 10 Binary version and spend the little effort to get your code PDFlib 10 ready.

It is usually worth it!

Rainer
  • 2,013
  • 1
  • 10
  • 7
  • Thanks for the answer. Can you please tell me how to prepare the object? I mean `$p->begin_document("", ""); ` look this code, how to make `$p`? – srvnk Jul 13 '23 at 07:14
  • `$p = new PDFlib();` does it work? @Rainer – srvnk Jul 13 '23 at 07:21
  • Thanks @Rainer. It worked. Let me see if there is any other issues. – srvnk Jul 13 '23 at 07:23
  • It worked but a water-mark on the pdf file. So the purpose was not solved. May I know why it is not possible to compile the source code? Why there is error `error: expected declaration or statement at end of input`? I checked and found that the syntax is ok. – srvnk Jul 13 '23 at 10:48
  • PDFlib GmbH has not maintained the PECL PDFlib package for 4 years. This means that the modifications required for PHP 8 have not been pushed to the PCEL PDFlib package, and it cannot be used for the latest PHP versions. But PDFlib GmbH provides binary packages of the latest version which you can work with. Either way, you need a license to use it. Therefore, it is certainly the easiest way to use the offered binaries right away. – Rainer Jul 13 '23 at 11:38