Bug 41601

Summary: Bug 38516 breaks PDF export for basket groups when using API2::PDF < 2.042
Product: Koha Reporter: Katrin Fischer <katrin.fischer>
Component: AcquisitionsAssignee: David Cook <dcook>
Status: Needs Signoff --- QA Contact: Testopia <testopia>
Severity: critical    
Priority: P5 - low CC: anna.leissle, cornelius.hertfelder, david, dcook, fridolin.somers
Version: Main   
Hardware: All   
OS: All   
GIT URL: Initiative type: ---
Sponsorship status: --- Comma delimited list of Sponsors:
Crowdfunding goal: 0 Patch complexity: ---
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
Circulation function:
Bug Depends on: 38516    
Bug Blocks:    
Attachments: Bug 41601: Create Koha::PDF::Loader wrapper for PDF::API2

Description Katrin Fischer 2026-01-13 14:42:40 UTC
We noticed that the PDF export for basket groups broke with the security update 24.11.11. We tracked it down to the change in bug 38516.

The error from the logs is:

Can't locate object method "to_string" via package "PDF::API2" at /usr/share/koha/lib/Koha/pdfformat/layout2pagesde.pm line 250.

The problem is that to_string and from_string only exist since 2.0.42. See change log:

https://metacpan.org/dist/PDF-API2/changes

    - Renamed several methods in the PDF::API2 base class:
      - end -> close
      - open_scalar -> from_string
      - stringify -> to_string
      - pages -> page_count
...

We are using packages with Debian 11. This seems to include 2.0.38.
Koha names the minimal required version as 2 on the about page.

I believe this means more libraries are probably affected.

Changing the method names to the old ones fixed the PDF export for us.
Comment 1 David Cook 2026-01-14 01:31:35 UTC
That's fun... but I do have an idea!
Comment 2 David Cook 2026-01-14 02:29:43 UTC
Created attachment 191398 [details] [review]
Bug 41601: Create Koha::PDF::Loader wrapper for PDF::API2

This patch adds a wrapper around PDF::API2 so that we can
use the right method names depending on the version of PDF::API2
being used when we're loading in PDF templates

Test plan:
0. Apply the patch and koha-plack --restart kohadev
1. chmod 444 /kohadevbox/koha/koha-tmpl/intranet-tmpl/prog/pdf/*.pdf
2. Create a basket with a vendor
3. Add an order to the basket
4. Close basket (and attach the basket to a new basket group with the same name)
5. Go to "Closed" tab and click "Export as PDF"
6. Note that there's no error and your PDF opens fine
7. Repeat the "Export as PDF" process for every option of the
system preference "OrderPdfFormat". Every option should work
without errors.
8. Celebrate!
Comment 3 David Cook 2026-01-14 02:32:32 UTC
Alternatively, I suppose we could subclass PDF::API2 and use our own namespace for names, but I thought this was a fairly light touch, which works well.

The unit test uses both the new and old method names, but this should still be tested on Debian 11 to make sure the automatic method name setting happens.

I've only tested this on Debian 12.