0

Registered users of my site can download some pdf's. I make use of the fpdf and fpdi class to add a watermark with their name to the pdf. Works fine, but the watermark is positioned on left/bottom corner. How can I center the watermark on the page?

<?php
require('fpdf/fpdf.php');
require_once 'FPDI/fpdi.php';

class PDF_Rotate extends FPDI {
    var $angle = 0;

    function Rotate($angle, $x = -1, $y = -1) {
        if ($x == -1)
            $x = $this->x;
        if ($y == -1)
            $y = $this->y;
        if ($this->angle != 0)
            $this->_out('Q');
        $this->angle = $angle;
        if ($angle != 0) {
            $angle*=M_PI / 180;
            $c = cos($angle);
            $s = sin($angle);
            $cx = $x * $this->k;
            $cy = ($this->h - $y) * $this->k;
            $this->_out(sprintf('q %.5F %.5F %.5F %.5F %.2F %.2F cm 1 0 0 1 %.2F %.2F cm', $c, $s, -$s, $c, $cx, $cy, -$cx, -$cy));
        }
    }

    function _endpage() {
        if ($this->angle != 0) {
            $this->angle = 0;
            $this->_out('Q');
        }
        parent::_endpage();
    }
}

Thanks!

miken32
  • 42,008
  • 16
  • 111
  • 154
  • 1
    I'd guess it has to do with whatever the values of `$this->x` and `$this->y` are when the function is called. – miken32 Nov 05 '18 at 16:13
  • First of all you should update to a recent version of FPDI! Then add the code which adds the watermark to your resulting PDF. This code is currently missing. – Jan Slabon Nov 12 '18 at 10:40

0 Answers0