Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

incorrect page numbering in PDF #29458

Closed
GildDart opened this issue Apr 24, 2024 · 19 comments
Closed

incorrect page numbering in PDF #29458

GildDart opened this issue Apr 24, 2024 · 19 comments
Labels
Bug This is a bug (something does not work as expected) Priority - High / Blocking This is a security hole or a bug that make a feature not possible to use or very expected feature.

Comments

@GildDart
Copy link

Bug

In v18.0.5 (php 8.0.30) the page numbering in the Propale pdf is incorrect. It is in the form: 1/2, 2/3, 3/4, 4/4 instead of 1/4, 2/4, 3/4, 4/4 (azure and cyan models).

On the same server and configuration it is correct for v17.0.3

Dolibarr Version

18.0.5

Environment PHP

8.0.3

Environment Database

10.6.17-MariaDB

Steps to reproduce the behavior and expected behavior

No response

Attached files

No response

@GildDart GildDart added the Bug This is a bug (something does not work as expected) label Apr 24, 2024
@sonikf
Copy link
Contributor

sonikf commented Apr 24, 2024

Hi @GildDart
Can you check if PDF_USE_GETALIASNBPAGE_FOR_TOTAL set to 1 fixes your problem and if numbering is in correct position?

@GildDart
Copy link
Author

Great it works !!!
Thank you sonikf.

@sonikf
Copy link
Contributor

sonikf commented Apr 25, 2024

Hi @GildDart
Can you reopen? This is actually a bug and is reproducible in 19.0.1 and 20.0.0-alpha

@GildDart GildDart reopened this Apr 25, 2024
@GildDart
Copy link
Author

Done...

@fappels fappels added the Priority - High / Blocking This is a security hole or a bug that make a feature not possible to use or very expected feature. label Apr 25, 2024
@fappels
Copy link
Contributor

fappels commented Apr 25, 2024

Have put this on high priority, had more complaints on this. Some Authorities do not accept invoices with incorrect page numbering.

@sonikf
Copy link
Contributor

sonikf commented Apr 25, 2024

Hi @fappels,
Can we collaborate on this?
Problem is here

// Show page nb only on iso languages (so default Helvetica font)
$pdf->SetXY($dims['wk'] - $dims['rm'] - 18 - getDolGlobalInt('PDF_FOOTER_PAGE_NUMBER_X', 0), -$posy - getDolGlobalInt('PDF_FOOTER_PAGE_NUMBER_Y', 0));
if (getDolGlobalString('PDF_USE_GETALIASNBPAGE_FOR_TOTAL')) {
// $pagination = $pdf->getAliasNumPage().' / '.$pdf->getAliasNbPages(); // works with $pdf->Cell
$pagination = $pdf->PageNo().' / '.$pdf->getAliasNbPages(); // seems to not work with all fonts like ru_UK
} else {
$pagination = $pdf->PageNo().' / '.$pdf->getNumPages(); // seems to always work even with $pdf->Cell. But some users have reported wrong nb (no way to reproduce)
}
$pdf->MultiCell(18, 2, $pagination, 0, 'R', 0);

For countries using Freemono or DejaVuSans instead of default Helvetica font only const PDF_USE_GETALIASNBPAGE_FOR_TOTAL works but renders wrong

2024-04-25_11-44
line 1365 should change from
$pdf->MultiCell(18, 2, $pagination, 0, 'R', 0);
to
$pdf->MultiCell(30, 2, $pagination, 0, 'R', 0);

@fappels
Copy link
Contributor

fappels commented Apr 25, 2024

Maybe make PR for V18 like:

if (in_array(pdf_getPDFFont($outputlangs), array('Freemono',  'DejaVuSans'))) {
    $pdf->MultiCell(30, 2, $pagination, 0, 'R', 0);
} else {
    $pdf->MultiCell(18, 2, $pagination, 0, 'R', 0);
}

and remove PDF_USE_GETALIASNBPAGE_FOR_TOTAL to keep only getAliasNbPages

@sonikf
Copy link
Contributor

sonikf commented Apr 25, 2024

@fappels , @GildDart
Can you test following code? It works for me in 18.0.5, 19.0.1 and 20.0.0-alpha

	// Show page nb only on iso languages (so default Helvetica font)
		$pdf->SetXY($dims['wk'] - $dims['rm'] - 18 - getDolGlobalInt('PDF_FOOTER_PAGE_NUMBER_X', 0), -$posy - getDolGlobalInt('PDF_FOOTER_PAGE_NUMBER_Y', 0));
		$pagination = $pdf->PageNo().' / '.$pdf->getAliasNbPages();
		if (in_array(pdf_getPDFFont($outputlangs), array('Freemono',  'DejaVuSans'))) {
    		$pdf->MultiCell(30, 2, $pagination, 0, 'R', 0);
		} else {
    		$pdf->MultiCell(18, 2, $pagination, 0, 'R', 0);
		}

fappels added a commit to fappels/dolibarr that referenced this issue Apr 25, 2024
@fappels
Copy link
Contributor

fappels commented Apr 25, 2024

@sonikf , @GildDart
Was still not working for 'Freemono', should be 'freemono'
Changed code also a bit, can you test?
I tested on all font found in main.lang

@GildDart
Copy link
Author

It is working with my v18.0.5.

@sonikf
Copy link
Contributor

sonikf commented Apr 25, 2024

@fappels
Somehow both 'Freemono' and 'freemono' works for me!
Tested again in 18.0.5, 19.0.1 and 20.0.0-alpha and it works!
Position with your code is a little bit off though even with $paginationWidth = 30;, can't figure out why...
freemono

2024-04-25_17-58

DejaVuSans

2024-04-25_17-40

@GildDart
is position ok for you?

@GildDart
Copy link
Author

Capture d’écran 2024-04-25 à 17 16 32

Could be a little lower and aligned at the right with the line above...

@fappels
Copy link
Contributor

fappels commented Apr 25, 2024

I put PR on draft, if you have better value for width and position I change in PR.

@GildDart
Copy link
Author

@fappels Where can I find the values ?

@sonikf
Copy link
Contributor

sonikf commented Apr 25, 2024

@fappels
Initial code you proposed worked better, apart from 'Freemono' and 'freemono' problem what else was wrong with your tests?

@GildDart
Did you test initial code proposal?
reposting with freemono correction....

	// Show page nb 
		$pdf->SetXY($dims['wk'] - $dims['rm'] - 18 - getDolGlobalInt('PDF_FOOTER_PAGE_NUMBER_X', 0), -$posy - getDolGlobalInt('PDF_FOOTER_PAGE_NUMBER_Y', 0));
		$pagination = $pdf->PageNo().' / '.$pdf->getAliasNbPages();
		if (in_array(pdf_getPDFFont($outputlangs), array('freemono',  'DejaVuSans'))) {
    		$pdf->MultiCell(30, 2, $pagination, 0, 'R', 0);
		} else {
    		$pdf->MultiCell(18, 2, $pagination, 0, 'R', 0);
		}

@fappels
Copy link
Contributor

fappels commented Apr 26, 2024

I pushed some correction, put 28 not 30, because think will have problem with doc more the 10 pages.
Also keep original alignment for standard font (others then freemone and DejaVuSans). Is patch for fix page numbering, not a patch for better alignment. Better alignment fix should be pushed only to V20.

@sonikf
Copy link
Contributor

sonikf commented Apr 26, 2024

Hi @fappels
ok much better now!

@GildDart
Copy link
Author

GildDart commented Apr 26, 2024

@sonikf

Here is what I put...

` // Show page nb only on iso languages (so default Helvetica font)

$pdf->SetXY($dims['wk'] - $dims['rm'] - 18 - getDolGlobalInt('PDF_FOOTER_PAGE_NUMBER_X', 0), -$posy - getDolGlobalInt('PDF_FOOTER_PAGE_NUMBER_Y', 0));

$pagination = $pdf->PageNo().' / '.$pdf->getAliasNbPages();

	if (in_array(pdf_getPDFFont($outputlangs), array('Freemono',  'DejaVuSans'))) {
		$pdf->MultiCell(30, 2, $pagination, 0, 'R', 0);
	} else {
		$pdf->MultiCell(18, 2, $pagination, 0, 'R', 0);
	}

`

instead of

`
// Show page nb only on iso languages (so default Helvetica font)
$pdf->SetXY($dims['wk'] - $dims['rm'] - 18 - getDolGlobalInt('PDF_FOOTER_PAGE_NUMBER_X', 0), -$posy - getDolGlobalInt('PDF_FOOTER_PAGE_NUMBER_Y', 0));

if (getDolGlobalString('PDF_USE_GETALIASNBPAGE_FOR_TOTAL')) {
	// $pagination = $pdf->getAliasNumPage().' / '.$pdf->getAliasNbPages(); 	// works with $pdf->Cell
	$pagination = $pdf->PageNo().' / '.$pdf->getAliasNbPages();	// seems to not works with all fonts like ru_UK
} else {
	$pagination = $pdf->PageNo().' / '.$pdf->getNumPages();		// seems to always work even with $pdf->Cell. But some users has reported wrong nb (no way to reproduce)
}

$pdf->MultiCell(18, 2, $pagination, 0, 'R', 0);

`

eldy pushed a commit that referenced this issue Apr 27, 2024
* FIX incorrect page numbering in PDF #29458

* Work on width correction

* Work on width correction

* Work on width correction

* Work on code order
@fappels
Copy link
Contributor

fappels commented Apr 27, 2024

I close this one, is now fixed in branch 18.
@sonikf & @GildDart , thanks for helping on this.

@fappels fappels closed this as completed Apr 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This is a bug (something does not work as expected) Priority - High / Blocking This is a security hole or a bug that make a feature not possible to use or very expected feature.
Projects
None yet
Development

No branches or pull requests

3 participants