phpcgccpdflibphp-8.2

PHP pdflib binary not working and also showing error in compiling


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.


Solution

  • 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:

    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!