dompdf and PHP8?

fstorch

Member
Since Akeeba started to complain about php 7.2 I gave php8 a try on a test-server.
Easily ran into that issue when trying to create a pdf with dompdf:
round(): Argument #1 ($num) must be of type int|float, string given
Call stack
#
Function Location
1 () JROOT/libraries/fabrik/vendor/dompdf/dompdf/src/Css/Style.php:3303
2 round() JROOT/libraries/fabrik/vendor/dompdf/dompdf/src/Css/Style.php:3303
3 Dompdf\Css\Style->set_z_index() JROOT/libraries/fabrik/vendor/dompdf/dompdf/src/Css/Style.php:888
4 Dompdf\Css\Style->__set() JROOT/libraries/fabrik/vendor/dompdf/dompdf/src/Css/Style.php:948
5 Dompdf\Css\Style->__get() JROOT/libraries/fabrik/vendor/dompdf/dompdf/src/Renderer.php:178
6 Dompdf\Renderer->render() JROOT/libraries/fabrik/vendor/dompdf/dompdf/src/FrameReflower/Page.php:148
7 Dompdf\FrameReflower\Page->reflow() JROOT/libraries/fabrik/vendor/dompdf/dompdf/src/FrameDecorator/AbstractFrameDecorator.php:895
8 Dompdf\FrameDecorator\AbstractFrameDecorator->reflow() JROOT/libraries/fabrik/vendor/dompdf/dompdf/src/Dompdf.php:815
9 Dompdf\Dompdf->render() JROOT/libraries/src/Document/PdfDocument.php:284
10 Joomla\CMS\Document\PdfDocument->render() JROOT/libraries/src/Application/CMSApplication.php:1112
11 Joomla\CMS\Application\CMSApplication->render() JROOT/libraries/src/Application/SiteApplication.php:778
12 Joomla\CMS\Application\SiteApplication->render() JROOT/libraries/src/Application/CMSApplication.php:231
13 Joomla\CMS\Application\CMSApplication->execute() JROOT/index.php:49

Did a Github Update but problem persists.
tried to cast to (int) or (float) but another error showed up elsewhere.

Has anybody been able to make dompdf run with php8?
Regards ... Franz
 
You could update the version of dompdf that fabrik is using. The current version is 2.0 and the installed fabrik version is 0.8.6
 
Has anyone experience with dompdf 2.0, Fabrik and php8?
No. Fabrik itself it not really php8 ready, please report issues you'll get.
At least you must use a Fabrik GitHub update (and if you are testing dompdf2.0 switch the dompdf folder afterwards as GitHub contains the old one).
 
I tried hard to get dompdf2.0 onto my testsite but fail e.g. with Class "Masterminds\HTML5" not found.
composer seems to fail (old version on my server) so I tried manually (copied the dirs from .zip, edited dompdf\vendor\composer\installed.json).
Do you - by chance - have a reference how I would get the newer dompdf into the site to work with fabrik?
 
I just tested replacing Fabrik's domPDF (0.8.6) with 1.2.2

Download the source zip, extract and move files to libraries/fabrik/vendor so that you have
libraries\fabrik\vendor\dompdf\dompdf with
/lib
/src
composer.json
etc
(you can rename the old dompdf before)

This seems to do with php8.

I assume dompdf 2.0 won't do without additional changes in Fabrik, there are "Breaking Changes" mentioned in GitHub
 
Thanxalot @troester .
I found out how to use composer (--ignore-platform-reqs) so I tried with dompdf 2.0 right away and it failed with an error that I cannot remember (response cannot be read?). So after some hours I retried and lo and behold the PDF showed up. It is missing the two-column layout though. So I downgraded to 1.2.2 with
Code:
composer require dompdf/dompdf:1.2.* --ignore-platform-reqs
and the PDF is generated as well. Single column as well but all images were incorrectly sized (to large).
So for now I will try to use 2.0.0:
Code:
cd <site>/libraries/fabrik/
composer require dompdf/dompdf --ignore-platform-reqs
and try to find out how to get my two-column layout back.
I remember this was a tough problem when I started with fabrik and dompdf.
And I hope dompdf 2.0.0 doesn't provide other surprises.
 
Correction: it works with Windows. On iOS the PDF still fails to download with
Safari kann die Seite nicht öffnen.
Fehler: „Parsen der Antwort nicht möglich"

Error: „Parsing of response not possible“
 
Good news! That iOS issue was caused by having Joomla debugging active (for the initial issue). As soon as I turned that off, the PDF worked in iOS as well. And it even shows the two-column layout.
Only issue left is to much spacing between the lines, so unexpected page-breaks occur.
Hope I can find that in my custom CSS, but that shouldn’t be a show-stopper. Other than that, PHP8 didn’t cause any headaches.
 
So you got domPDF2.0 running?
to much spacing between the lines
You should be able to examine with PDFdebug on in your browser what may cause the spacing (e.g. <p or <tr or <td tags may have default spacing/padding/margin set (in the PDF lib)

I find it helpful to add different background and/or borders for those tags to the PDF template so you can see the extend in the generated PDF.
 
Last edited:
Sorry for the delay but even with all the tricks and suggestions, it wasn’t obvious, what has to be changed. I had to generate zillions of PDF‘s. But I finally succeeded yesterday.
My PDF looks good again with PHP8 and DOMPDF 2.0.

So far didn’t run into any more PHP8 errors, though I will have to test the site and backend more.
Is there anything, that might be in focus for causing issues?


Gesendet von iPhone mit Tapatalk Pro
 
Update: Before touching the production site, I did another github update of a test site and had to find that composer 1.10.1 faces an issue with PHP8: https://github.com/composer/composer/issues/9097
My hoster did an upgrade to composer 2.4.1 for me,which fixed that bug.
Had to modify the call to make it work again:
Code:
composer require dompdf/dompdf --ignore-platform-reqs --with-all-dependencies
Test Site works fine again with PHP8 adn dompdf 2.0.
Production hoster doesn't allow wget and composer, so I'll have some more fun with it.
 
hi @fstorch ,
Can you please write down here stepwise guide to upgrade domopdf library to latest 2.0, so that it will help others too.

As mentioned in Github, the dompdf has some major changes, specially in Canvas. Are you facing any issue in fabrik Sign Element plugin after upgrade ?
 
hi @fstorch ,
Can you please write down here stepwise guide to upgrade domopdf library to latest 2.0, so that it will help others too.

As mentioned in Github, the dompdf has some major changes, specially in Canvas. Are you facing any issue in fabrik Sign Element plugin after upgrade ?

Sorry didn’t get any notification.
I will post my current user modifications as soon as I find time.
I don‘t use a Sign element in my forms.
Just a fileupload for images, which still runs fine.


Gesendet von iPhone mit Tapatalk Pro
 
After the usual WGET to update Fabrik, I ran
Code:
cd libraries/fabrik/
composer require dompdf/dompdf --ignore-platform-reqs --with-all-dependencies
which shows:
Code:
Using version ^2.0 for dompdf/dompdf                                                                                                                               
./composer.json has been updated                                                                                                                                   
Running composer update dompdf/dompdf --with-all-dependencies                                                                                                      
Loading composer repositories with package information                                                                                                             
Updating dependencies                                                                                                                                              
Lock file operations: 1 install, 4 updates, 0 removals                                                                                                             
  - Upgrading dompdf/dompdf (v0.8.6 => v2.0.0)                                                                                                                     
  - Locking masterminds/html5 (2.7.6)                                                                                                                              
  - Upgrading phenx/php-font-lib (0.5.2 => 0.5.4)                                                                                                                  
  - Upgrading phenx/php-svg-lib (v0.3.3 => 0.4.1)                                                                                                                  
  - Upgrading sabberworm/php-css-parser (8.3.1 => 8.4.0)                                                                                                           
Writing lock file                                                                                                                                                  
Installing dependencies from lock file (including require-dev)                                                                                                     
Package operations: 1 install, 4 updates, 0 removals                                                                                                               
  - Upgrading sabberworm/php-css-parser (8.3.1 => 8.4.0): Extracting archive                                                                                       
  - Upgrading phenx/php-svg-lib (v0.3.3 => 0.4.1): Extracting archive                                                                                              
  - Upgrading phenx/php-font-lib (0.5.2 => 0.5.4): Extracting archive                                                                                              
  - Installing masterminds/html5 (2.7.6): Extracting archive                                                                                                       
  - Upgrading dompdf/dompdf (v0.8.6 => v2.0.0): Extracting archive                                                                                                 
Package popphp/pop-shipping is abandoned, you should avoid using it. No replacement was suggested.                                                                 
Generating autoload files                                                                                                                                          
Found 6 security vulnerability advisories affecting 2 packages.                                                                                                    
Run composer audit for a full list of advisories.

I only had to modify custom_css.php in my custom pdf template.
I will upload it as a reference.

This is all still done on my Test Site, which conveniently allows wget and a current composer.
The tricky part is that my production provider doesn't allow WGET and composer (for security reasons).
I will have to modify a master.zip with the dompdf 2.0 requirements (sabberworm, phenx, masterminds).
In addition to replace the directories, it will require to modify some composer files, to make autoload work.
Will keep you posted on that progress.
 

Attachments

  • custom_css.zip
    2.1 KB · Views: 24
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top