2016-04-23 82 views
0

我正在使用FPDI在圖像頂部導入PDF。我有一切工作,但現在我想旋轉圖像。這裏是我的代碼:PHP - FPDI - 旋轉圖像

require('fpdf.php'); 
    require('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(); 
     } 

    } 

    function RotatedImage($file,$x,$y,$w,$angle) 
    { 
    //Image rotated around its upper-left corner 
    $this->Rotate($angle,$x,$y); 
    $this->Image($file,$x,$y,$w); 
    $this->Rotate(0); 
    } 

    $pdf = new FPDI(); 

    $pdf->AddPage(); 

    //$pdf->Image('template/test.jpg',14,26,150); 
    $pdf->RotatedImage('template/test.jpg',14,26,150,4); 


    //load template 
    $pdf->setSourceFile('template/photo.pdf'); 
    $tplIdx = $pdf->importPage(1); 
    $pdf->SetAutoPagebreak(false, 0); 

    //use the imported page and place it at point 0,0; calculate width and height 
    //automaticallay and ajust the page size to the size of the imported page 
    $pdf->useTemplate($tplIdx, 0, 0, 210.058, 296.926, true); 

    $pdf->Output(); 

該行正常工作:

$pdf->Image('template/test.jpg',14,26,150); 

但是,如果我嘗試以下方法:

$pdf->RotatedImage('template/test.jpg',14,26,150,4); 

我得到一個錯誤:FPDI:RotatedImage不確定的。

我試圖讓FPDF旋轉法(http://www.fpdf.org/en/script/script2.php)與FPDI(https://www.setasign.com/products/fpdi/about/

工作有沒有人管理這之前?

回答

0

將你的RotatedImage()函數放入你的班級。

它沒有定義,因爲它試圖執行$pdf上的函數,但它當前存在於類之外,所以它沒有看到它。