Skip to content

FIX #40005: Correct text truncation for PDFs (now correct when MAIN_DISABLE_TRUNC is on) - #40126

Open
mdeweerd wants to merge 4 commits into
Dolibarr:developfrom
mdeweerd:pdf/truncate
Open

FIX #40005: Correct text truncation for PDFs (now correct when MAIN_DISABLE_TRUNC is on)#40126
mdeweerd wants to merge 4 commits into
Dolibarr:developfrom
mdeweerd:pdf/truncate

Conversation

@mdeweerd

@mdeweerd mdeweerd commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

FIX #40005: Correct text truncation for PDFs (now correct when MAIN_DISABLE_TRUNC is on)

This commit replaces all instances of dol_trunc with the new pdfTruncateText method in various PDF generation modules.

This is required to cope with MAIN_DISABLE_TRUNC=1 which converts dol_trunc to a no-op because of CSS based truncation. PDF does not rely on CSS.

@mdeweerd mdeweerd changed the title FIX #40005: Correct text truncation for PDFs (incorrect when MAIN_DIS… FIX #40005: Correct text truncation for PDFs (incorrect when MAIN_DISABLE_TRUNC is on) Sep 6, 2026
@mdeweerd

mdeweerd commented Sep 6, 2026

Copy link
Copy Markdown
Contributor Author

OK to backport ?

@mdeweerd mdeweerd changed the title FIX #40005: Correct text truncation for PDFs (incorrect when MAIN_DISABLE_TRUNC is on) FIX #40005: Correct text truncation for PDFs (now correct when MAIN_DISABLE_TRUNC is on) Sep 6, 2026
@pixodeo

pixodeo commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

The approach is right, measuring against real PDF width instead of counting characters, and making it independent of MAIN_DISABLE_TRUNC solves the masking concern I raised on the issue. Two problems with the IBAN call sites though, both from the signature change.

The two signatures do not line up:

dol_trunc($string, $size, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
pdfTruncateText($pdf, $text, $max_width, $ellipsis_pos=1, $ellipsis="…")

and the call was converted positionally:

$this->pdfTruncateText($pdf, $iban, 6, 'right', 'UTF-8', 1)

Traced through your own mapping code, that resolves to:

max_width    = 6
ellipsis_pos = 0          ('right' is mapped to 0)
ellipsis     = 'UTF-8'    <- the encoding argument lands in the ellipsis string

So the ellipsis becomes the literal text "UTF-8", and the trailing 1, which was $nodot in the old call, is silently dropped. With ellipsis_pos 0 the ellipsis is blanked, so it may not surface visually, but the argument is still wrong and would bite if the position ever changed.

Second and more important, 6 no longer means the same thing. In dol_trunc it was six characters, in pdfTruncateText it is six user units of width, so millimetres. Six millimetres fits roughly two characters at a normal font size, not six, so the masked IBAN gets shorter than intended. Worth checking on a generated invoice.

Affected sites, all three the same pattern:

facture/doc/pdf_crabe.modules.php
facture/doc/pdf_octopus.modules.php
facture/doc/pdf_sponge.modules.php

Those three are the masking case rather than layout, and they are the ones I flagged on #40005: they exist to print only the start of a bank account number on a customer-facing invoice. Getting the width wrong there shows fewer characters, which is harmless, but the argument shift is worth fixing regardless so the next person reading it is not misled.

Everything else in the diff, the Project title and RefCustomer conversions, looks right to me since those are genuine layout truncations against a MultiCell width.

@mdeweerd
mdeweerd force-pushed the pdf/truncate branch 2 times, most recently from 440c92b to e60f0f9 Compare September 7, 2026 15:48
@eldy

eldy commented Sep 7, 2026

Copy link
Copy Markdown
Member

OK to backport ?

This looks a structural change that may have a lot of side effect, so it is a change not elligible for backport on past stable versions.
Also option MAIN_DISABLE_TRUNC is not a feature but a dev feature to help to make a transition of this change for future version.

@eldy eldy added the PR OK to merge PR was analyzed by PR merger and seems ok to be validated. Merge may occurs soon... label Sep 7, 2026
…MAIN_DISABLE_TRUNC is on)

# FIX Dolibarr#40005: Correct text truncation for PDFs (incorrect when MAIN_DISABLE_TRUNC is on)

This commit replaces all instances of dol_trunc with the new pdfTruncateText method in various PDF generation modules.

This is required to cope with `MAIN_DISABLE_TRUNC=1` which converts dol_trunc to a no-op because of CSS based truncation.
PDF does not rely on CSS.
# Fix: Remove UTF-8 encoding parameter in pdfTruncateText calls

The changes remove the UTF-8 encoding parameter from pdfTruncateText calls in the following files:
- htdocs/core/modules/action/doc/pdf_standard_actions.class.php
- htdocs/core/modules/facture/doc/pdf_octopus.modules.php
- htdocs/core/modules/facture/doc/pdf_sponge.modules.php

This parameter is not needed after changing dol_substr to pdfTruncateText.

Highlighted by @pixodeo.
The pdfTruncateText method has been moved from CommonDocGenerator class to pdf.lib.php and renamed to pdf_truncate_text.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR OK to merge PR was analyzed by PR merger and seems ok to be validated. Merge may occurs soon...

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect text cut-offs

3 participants