FPDF每页都有水印

FPDF water mark in every page

我正在尝试在 PDF 上添加水印,它在单页上工作正常,但是当内容是多页时,它只会在第一页上添加水印。我如何才能在每个页面上添加水印页。是否可以在 FPDF.Any 帮助中插入图像而不是文本,我们将不胜感激。

class PDF_Rotate extends FPDF
{
    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();
    }
}

    class mypdf extends PDF_Rotate{

function Header1()
    {
    /* Put the watermark */
    $this->SetFont('Arial','B',50);
    $this->SetTextColor(225,225,225);
    $this->RotatedText(35,190,'I U A C',45);
    //$this->RotatedText(135,190,'I U A C',45);
    $this->RotatedText(235,190,'I U A C',45);
    $this->RotatedText(95,160,'GEOCHRONOLOGY',45);
    $this->RotatedText(65,70,'I U A C',45);
    //$this->RotatedText(135,60,'I U A C',45);
    $this->RotatedText(235,70,'I U A C',45);
    }

    function RotatedText($x, $y, $txt, $angle)
    {
    /* Text rotated around its origin */
    $this->Rotate($angle,$x,$y);
    $this->Text($x,$y,$txt);
    $this->Rotate(0);
    }
    function Footer()
    {

        // Position at 1.5 cm from bottom
        $this->SetY(179);
        // Arial italic 8
        $this->SetFont('Arial','I',8);
        // Text color in gray
        $this->SetTextColor(128);
        // Page number
        $this->Cell(0,10,'Page '.$this->PageNo(),0,0,'C');
$pdf = new mypdf();
$pdf->AliasNbPages();
$pdf->AddPage('L','A4',0);
$pdf->Header1();
$pdf->headerTable();
$pdf->viewTable();
$pdf->footer();
$pdf->output();

扩展 Shubham Baranwal 和 Dave 告诉你的...你应该将 Header 方法添加到你的 "PDF_Rotate" class 并且在该方法中是您将在其中添加水印。

据我所知,您有一个名为 Header1 的方法,只需将其重命名为 Header.

对于插入图像也应该是相同的过程,只需在 Header 方法中添加图像,它就会被复制。