diff --git a/htdocs/core/modules/fichinter/doc/pdf_soleil.modules.php b/htdocs/core/modules/fichinter/doc/pdf_soleil.modules.php index 3a4bed05fe5f6..aba89bd3235a0 100644 --- a/htdocs/core/modules/fichinter/doc/pdf_soleil.modules.php +++ b/htdocs/core/modules/fichinter/doc/pdf_soleil.modules.php @@ -508,31 +508,41 @@ protected function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $ } } - // EN: Keep the signature box and related labels on the same page by positioning them dynamically. - $signature_block_height = 30; - $page_break_trigger = $pdf->getPageHeight() - $pdf->getBreakMargin(); - $signature_top = $tab_top + $tab_height - $signature_block_height - 5; - $signature_top = min($signature_top, $page_break_trigger - $signature_block_height); - $signature_top = max($signature_top, $tab_top + 5); + // EN: Keep the signature boxes aligned inside the rectangle while preventing overflow. + $signature_block_height = 30; + $tab_bottom = $tab_top + $tab_height; + $page_break_trigger = $pdf->getPageHeight() - $pdf->getBreakMargin(); + $content_bottom = max($nexY, $tab_top + 6); + $signature_top = $tab_bottom - $signature_block_height - 6; + $signature_top = max($signature_top, $content_bottom + 2); + $signature_top = min($signature_top, $tab_bottom - $signature_block_height - 1); + $signature_top = min($signature_top, $page_break_trigger - $signature_block_height); + + $available_signature_width = $this->page_largeur - $this->marge_gauche - $this->marge_droite; + $signature_spacing = 5; + $signature_box_width = ($available_signature_width - $signature_spacing) / 2; + $signature_left_x = $this->marge_gauche; + $signature_right_x = $signature_left_x + $signature_box_width + $signature_spacing; $previous_autopagebreak = $pdf->getAutoPageBreak(); $previous_breakmargin = $pdf->getBreakMargin(); $pdf->SetAutoPageBreak(false, 0); - $pdf->SetXY(20, $signature_top); - $pdf->MultiCell(80, 5, $outputlangs->transnoentities("NameAndSignatureOfInternalContact"), 0, 'L', 0); + $pdf->SetXY($signature_left_x, $signature_top); + $pdf->MultiCell($signature_box_width, 5, $outputlangs->transnoentities("NameAndSignatureOfInternalContact"), 0, 'L', 0); - $pdf->SetXY(20, $signature_top + 5); - $pdf->MultiCell(80, 25, $employee_name, 1, 'L'); + $pdf->SetXY($signature_left_x, $signature_top + 5); + $pdf->MultiCell($signature_box_width, 25, $employee_name, 1, 'L'); - $pdf->SetXY(110, $signature_top); - $pdf->MultiCell(80, 5, $outputlangs->transnoentities("NameAndSignatureOfExternalContact"), 0, 'L', 0); + $pdf->SetXY($signature_right_x, $signature_top); + $pdf->MultiCell($signature_box_width, 5, $outputlangs->transnoentities("NameAndSignatureOfExternalContact"), 0, 'L', 0); - $pdf->SetXY(110, $signature_top + 5); - $pdf->MultiCell(80, 25, '', 1); + $pdf->SetXY($signature_right_x, $signature_top + 5); + $pdf->MultiCell($signature_box_width, 25, '', 1); $pdf->SetAutoPageBreak($previous_autopagebreak, $previous_breakmargin); } + } // phpcs:disable PEAR.NamingConventions.ValidFunctionName.PublicUnderscore