Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/performance/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在codeigniter中下载已存在的pdf文件时添加用户名作为水印_Codeigniter_Fpdf_Fpdi - Fatal编程技术网

在codeigniter中下载已存在的pdf文件时添加用户名作为水印

在codeigniter中下载已存在的pdf文件时添加用户名作为水印,codeigniter,fpdf,fpdi,Codeigniter,Fpdf,Fpdi,我想实现的是,每当用户从系统下载pdf文件时,都会在文件中添加带有其用户名的水印。我已经看过了,但还没有完全理解(它使用本机PHP)。您可以使用下面的代码下载水印文件 public function doWaterMark() { $currentFile = $this->file; //$currentFile = put here your file; $Username = "UserName";

我想实现的是,每当用户从系统下载pdf文件时,都会在文件中添加带有其用户名的水印。我已经看过了,但还没有完全理解(它使用本机PHP)。

您可以使用下面的代码下载水印文件

 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');
    }
公共函数doWaterMark() { $currentFile=$this->file; //$currentFile=将您的文件放在这里; $Username=“Username”; $this->pdf=new FPDI(); $pagecount=$this->pdf->setSourceFile($currentFile); 对于($i=1;$i pdf->addPage();//pdf->importPage($i); $this->pdf->usemplate($tplidx,10,10100); //现在在导入的页面上方写一些文本 $this->pdf->SetFont('Arial','I',40); $this->pdf->SetTextColor(255,0,0); $this->pdf->SetXY(25135); $this->_旋转(55); $this->pdf->Write(0,$Username); $this->_rotate(0);//pdf->Output('New File Name','F'); }
您做了什么?是否有任何错误?显示一些代码!