-1

What I want to achieve is that whenever a user downloads a pdf file from the system, a watermark with his/her Username is added to the file. I have had a look at this link but I haven't got around it (it uses native PHP).

1 Answers1

0

You can use for the watermark downloaded file the below code.

 public function doWaterMark()
    {
        $currentFile = $this->file;
        //$currentFile = put here your file;
        $Username = "UserName";
        $this->pdf = new FPDI();

        $pagecount = $this->pdf->setSourceFile($currentFile);

        for ($i = 1; $i <= $pagecount; $i++) {
            $this->pdf->addPage(); //<- moved from outside loop
            $tplidx = $this->pdf->importPage($i);
            $this->pdf->useTemplate($tplidx, 10, 10, 100);
            // now write some text above the imported page
            $this->pdf->SetFont('Arial', 'I', 40);
            $this->pdf->SetTextColor(255, 0, 0);
            $this->pdf->SetXY(25, 135);
            $this->_rotate(55);
            $this->pdf->Write(0, $Username);
            $this->_rotate(0); //<-added
        }

        $this->pdf->Output('New File Name', 'F');
    }