2016-09-11 2 views
1

모든 페이지의 오른쪽 상단에 워터 마크 이미지가있는 pdf를 생성하는 스크립트가 있습니다. 그것은 PDF로 변환 된 PNG 이미지가있을 때를 제외하고는 정상적으로 작동합니다. 워터 마크는 PDF의 이미지 뒤에 나타납니다. 워터 마크를 PDF 페이지의 모든 요소 앞에 표시되도록 우선 순위를 매기는 방법이 있습니까?FPDF/FPDI 워터 마크가 페이지 뒤쪽으로 이동합니다.

<?php 
//This page contains edit the existing file by using fpdi. 
require('include/fpdf/fpdf.php'); 
require_once 'include/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(); 
    } 

} 

$fullPathToFile = "file.pdf"; 

class PDF extends PDF_Rotate { 

    var $_tplIdx; 

    function Header() { 
     global $fullPathToFile; 

     //Put the watermark 
     $this->Image("https://example.com/watermark.png", 160, 0, 50, 0, 'PNG'); //[0] = how much right, [1] = the less, the higher. 
     $this->SetFont('Arial', 'B', 50); 
     $this->SetTextColor(255, 192, 203); 
     $this->RotatedText(20, 230, '', 45); 

     if (is_null($this->_tplIdx)) { 

      // THIS IS WHERE YOU GET THE NUMBER OF PAGES 
      $this->numPages = $this->setSourceFile($fullPathToFile); 
      $this->_tplIdx = $this->importPage(1); 
     } 
     $this->useTemplate($this->_tplIdx, 0, 0, 200); 


    } 

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

} 

# ========================== 

$pdf = new PDF(); 
//$pdf = new FPDI(); 
$pdf->AddPage(); 
$pdf->SetFont('Arial', '', 12); 


/*$txt = "FPDF is a PHP class which allows to generate PDF files with pure PHP, that is to say " . 
     "without using the PDFlib library. F from FPDF stands for Free: you may use it for any " . 
     "kind of usage and modify it to suit your needs.\n\n"; 
for ($i = 0; $i < 25; $i++) { 
    $pdf->MultiCell(0, 5, $txt, 0, 'J'); 
}*/ 


if($pdf->numPages>1) { 
    for($i=2;$i<=$pdf->numPages;$i++) { 
     //$pdf->endPage(); 
     $pdf->_tplIdx = $pdf->importPage($i); 
     $pdf->AddPage(); 
    } 
} 

$pdf->Output(); 
?> 

답변

0

스크립트가 다소 이상하고 혼란 :

내 코드입니다. 그러나 주된 질문은 간단합니다. Image() 또는 텍스트 메소드를 호출하기 전에 가져온 페이지를 사용하고 이후에는 사용하지 마십시오.

관련 문제