Bug 29994 - Single label PDF export not working
Summary: Single label PDF export not working
Status: RESOLVED DUPLICATE of bug 31220
Alias: None
Product: Koha
Classification: Unclassified
Component: Label/patron card printing (show other bugs)
Version: unspecified
Hardware: All All
: P3 critical with 10 votes (vote)
Assignee: Chris Nighswonger
QA Contact: Testopia
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-02-01 13:52 UTC by Isabel Pineda
Modified: 2022-08-02 17:52 UTC (History)
4 users (show)

See Also:
Change sponsored?: ---
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Isabel Pineda 2022-02-01 13:52:00 UTC
Since update from 21.05 to 21.11 the export of single labels to pdf is not working anymore. If there are at least 2 labels in a label batch, it works, but single labels cannot be exported to pdf.
 
I have just updated from 21.11.01 to 21.11.02, but in the new version this has not been fixed yet.
Comment 1 Katrin Fischer 2022-02-19 20:49:12 UTC
It appears to be working on master. 

Isabel, could you add some more information about your setup for the labels?
Comment 2 Isabel Pineda 2022-02-21 19:59:18 UTC
Hi Katrin. 
Of course. The template is set this way:
page height: 2.5 cm
page width: 5 cm
label width: 5.8 cm
label height: 4 cm

top page margin: -0.6 cm
left page margin: 0 cm
top text margin: 1.3 cm
left text margin: 0 cm
number of columns: 1
number of rows: 1
gap between columns: 0 cm
gap between rows: 0 cm

The label layout:

barcode type: Code 39
layout type: BIBBAR
Data fields: itemcallnumber
Text justification: left
Font: Helvetica
Font size: 12
Oblique title: yes


The problem is that an empty pdf file is generated when I there is only a single label. If it is a batch with at least 2 labels, it works fine.
It used to work for me with single labels and the same settings before version 21.11.
Comment 3 Caroline Cyr La Rose 2022-07-12 16:21:41 UTC
The problem occurs when clicking the "Export" button in the table of items, Actions column. 

To test:
1) If you do not already have label templates and layouts, add some (can use the settings in comment 2, but any will do)
2) Go to Tools > Label creator > New > Label batch
3) Add one barcode in the box
4) Click Add items
5) Click the 'Export full batch' button
6) Choose the label template and layout
7) Click Export
8) Click Download as PDF
--> PDF is generated
9) In the label batch, select the item (the checkbox on the right)
10) Click 'Export selected items'
11) Repeat steps 6-8
--> PDF is generated
12) In the label batch, click the 'Export' button in the Actions column
13) Repeat steps 6-8
--> No PDF is generated
Comment 4 Manos PETRIDIS 2022-07-18 19:35:00 UTC
Could this be related to https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=28806 ?
Comment 5 Isabel Pineda 2022-07-18 19:41:58 UTC
(In reply to Caroline Cyr La Rose from comment #3)
> The problem occurs when clicking the "Export" button in the table of items,
> Actions column. 
> 
> To test:
> 1) If you do not already have label templates and layouts, add some (can use
> the settings in comment 2, but any will do)
> 2) Go to Tools > Label creator > New > Label batch
> 3) Add one barcode in the box
> 4) Click Add items
> 5) Click the 'Export full batch' button
> 6) Choose the label template and layout
> 7) Click Export
> 8) Click Download as PDF
> --> PDF is generated
> 9) In the label batch, select the item (the checkbox on the right)
> 10) Click 'Export selected items'
> 11) Repeat steps 6-8
> --> PDF is generated
> 12) In the label batch, click the 'Export' button in the Actions column
> 13) Repeat steps 6-8
> --> No PDF is generated

Thank you. Yes, this way it works, at least it does now that I upgraded to version 22.05. I remember that the single export button in the table used to work in Koha 21.05 and previous versions.
Comment 6 Isabel Pineda 2022-07-18 19:43:44 UTC
(In reply to Manos PETRIDIS from comment #4)
> Could this be related to
> https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=28806 ?

Thank you. No, in my case all printed characters are Latin characters.
Comment 7 Isabel Pineda 2022-07-18 20:38:33 UTC
(In reply to Isabel Pineda from comment #6)
> (In reply to Manos PETRIDIS from comment #4)
> > Could this be related to
> > https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=28806 ?
> 
> Thank you. No, in my case all printed characters are Latin characters.

We are using Koha in Spanish, though. Maybe this has something to do with the problem.
Comment 8 Lucas Gass 2022-07-27 00:03:14 UTC
I am able to recreate this in current master. 

1. Make a label batch. 
2. Go to 'label-edit-batch.pl' and select at least one item in the table. ( #batcht )
3. Use the 'Export' button to export at one item. 
4. Choose template/layout etc.
5. Download as PDF

This is the error I see:
Can't locate object method "get_attr" via package "-2" (perhaps you forgot to load "-2"?) at /kohadevbox/koha/labels/label-create-pdf.pl line 127
Comment 9 Chris Nighswonger 2022-07-27 00:38:39 UTC
(In reply to Lucas Gass from comment #8)

> This is the error I see:
> Can't locate object method "get_attr" via package "-2" (perhaps you forgot
> to load "-2"?) at /kohadevbox/koha/labels/label-create-pdf.pl line 127

See the comment here:

https://github.com/Koha-Community/Koha/blob/master/C4/Creators/Batch.pm#L156

What is being passed in as the batch id?
Comment 10 Chris Nighswonger 2022-07-27 00:59:22 UTC
(In reply to Chris Nighswonger from comment #9)
> (In reply to Lucas Gass from comment #8)
> 
> > This is the error I see:
> > Can't locate object method "get_attr" via package "-2" (perhaps you forgot
> > to load "-2"?) at /kohadevbox/koha/labels/label-create-pdf.pl line 127
> 
> See the comment here:
> 
> https://github.com/Koha-Community/Koha/blob/master/C4/Creators/Batch.pm#L156
> 
> What is being passed in as the batch id?

At a minimum this error should be trapped here:

https://github.com/Koha-Community/Koha/blob/master/labels/label-create-pdf.pl#L59
Comment 11 Chris Nighswonger 2022-07-27 01:09:12 UTC
(In reply to Chris Nighswonger from comment #9)
> (In reply to Lucas Gass from comment #8)
> 
> > This is the error I see:
> > Can't locate object method "get_attr" via package "-2" (perhaps you forgot
> > to load "-2"?) at /kohadevbox/koha/labels/label-create-pdf.pl line 127
> 
> See the comment here:
> 
> https://github.com/Koha-Community/Koha/blob/master/C4/Creators/Batch.pm#L156
> 
> What is being passed in as the batch id?

The URL to create the PDF should similar to this:

https://jl-staff.campus.foundations.edu/cgi-bin/koha/labels/label-create-pdf.pl?batch_id=858&template_id=1&layout_id=5&start_label=1&label_id=25498

If batch_id is non-existent or an invalid value, C4::Creators::Batch->retrieve will return -2.
Comment 12 Chris Nighswonger 2022-07-27 01:20:58 UTC
(In reply to Lucas Gass from comment #8)
> I am able to recreate this in current master. 
> 
> 1. Make a label batch. 
> 2. Go to 'label-edit-batch.pl' and select at least one item in the table. (
> #batcht )

batch_id originates from element_id passed in to label-edit-batch.pl. ie.

https://jl-staff.campus.foundations.edu/cgi-bin/koha/labels/label-edit-batch.pl?op=edit&element_id=858

> 3. Use the 'Export' button to export at one item. 
> 4. Choose template/layout etc.

The fact that you are able to get this far would seem to indicate that a valid batch_id is being passed in to this point.

> 5. Download as PDF
> 
> This is the error I see:
> Can't locate object method "get_attr" via package "-2" (perhaps you forgot
> to load "-2"?) at /kohadevbox/koha/labels/label-create-pdf.pl line 127

It appears that by the time you get to this point, the batch_id has become corrupted somehow.

Please post both the label-edit-batch.pl URL and the label-create-pdf-pl URL for your failure case.
Comment 13 Chris Nighswonger 2022-08-02 00:42:02 UTC
If one of the folks experiencing this issue could post both the label-edit-batch.pl URL and the label-create-pdf.pl URL for your failure case, please.

Also, please post the output from the following query limited by the batch_id of your failure case:

SELECT * FROM creator_batches WHERE batch_id=<your-batch_id-here>;
Comment 14 Chris Nighswonger 2022-08-02 01:29:14 UTC
(In reply to Caroline Cyr La Rose from comment #3)
> The problem occurs when clicking the "Export" button in the table of items,

This is important. There are two separate JS functions which are attached to these export "options." The Export button triggers one[1] while the 'Export selected items' triggers another[2]. In the former, batch_id is passed in via a TT variable; in the latter it is extracted from the data value of the element. I wonder if the latter is munged up somehow... If so, this could explain the discrepancy I mentioned in comment #12.

So what we need to see is the resulting URL generated by each of these functions. Perhaps someone with the issue can grab these from the network tab in the browser debug console and post them here?


[1] https://github.com/Koha-Community/Koha/blob/cdf34ce15603edfee5453ce7b232d2ceb0aa61e7/koha-tmpl/intranet-tmpl/prog/en/modules/labels/label-edit-batch.tt#L353

[2] https://github.com/Koha-Community/Koha/blob/cdf34ce15603edfee5453ce7b232d2ceb0aa61e7/koha-tmpl/intranet-tmpl/prog/en/modules/labels/label-edit-batch.tt#L364
Comment 15 Chris Nighswonger 2022-08-02 01:34:12 UTC
Former and latter should be swapped in comment #14... where's the edit comment options when you need it? ;-P
Comment 16 Lucas Gass 2022-08-02 17:45:49 UTC

*** This bug has been marked as a duplicate of bug 31220 ***
Comment 17 Chris Nighswonger 2022-08-02 17:52:29 UTC
Good catch. Thanks!