From 16d530b22d9ec62fc500334eb13bbd977e65464e Mon Sep 17 00:00:00 2001
From: Laurent Destailleur <eldy@destailleur.fr>
Date: Thu, 25 Jul 2013 18:56:09 +0200
Subject: [PATCH] Fix: Watermark make pagebreak crazy.

---
 htdocs/core/lib/pdf.lib.php | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/htdocs/core/lib/pdf.lib.php b/htdocs/core/lib/pdf.lib.php
index d6d846c2b23..098ad08812e 100644
--- a/htdocs/core/lib/pdf.lib.php
+++ b/htdocs/core/lib/pdf.lib.php
@@ -407,19 +407,24 @@ function pdf_watermark(&$pdf, $outputlangs, $h, $w, $unit, $text)
 	elseif ($unit=='cm') $k=72/2.54;
 	elseif ($unit=='in') $k=72;
 
-	$watermark_angle=atan($h/$w);
-	$watermark_x=5;
-	$watermark_y=$h-50; // We must be sure to not print into margins
-	$watermark_width=$h;
-	$pdf->SetFont('','B',50);
+	$savx=$pdf->getX(); $savy=$pdf->getY();
+	
+	$watermark_angle=atan($h/$w)/2;
+	$watermark_x_pos=0;
+	$watermark_y_pos=$h/3;
+	$watermark_x=$w/2;
+	$watermark_y=$h/3;
+	$pdf->SetFont('','B',40);
 	$pdf->SetTextColor(255,192,203);
 	//rotate
 	$pdf->_out(sprintf('q %.5F %.5F %.5F %.5F %.2F %.2F cm 1 0 0 1 %.2F %.2F cm',cos($watermark_angle),sin($watermark_angle),-sin($watermark_angle),cos($watermark_angle),$watermark_x*$k,($h-$watermark_y)*$k,-$watermark_x*$k,-($h-$watermark_y)*$k));
 	//print watermark
-	$pdf->SetXY($watermark_x,$watermark_y);
-	$pdf->Cell($watermark_width,25,$outputlangs->convToOutputCharset($text),0,2,"C",0);
+	$pdf->SetXY($watermark_x_pos,$watermark_y_pos);
+	$pdf->Cell($w-20,25,$outputlangs->convToOutputCharset($text),"",2,"C",0);
 	//antirotate
 	$pdf->_out('Q');
+
+	$pdf->SetXY($savx,$savy);
 }
 
 
-- 
GitLab