我正在使用FPDI在图像顶部导入PDF。我有一切正常,但现在我想旋转图像。这是我的代码:
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 undefined。
我试图让FPDF Rotate方法(http://www.fpdf.org/en/script/script2.php)与FPDI(https://www.setasign.com/products/fpdi/about/)一起工作
以前有人管理过吗?
答案 0 :(得分:1)
将RotatedImage()
功能放入班级。
它是未定义的,因为它试图在$pdf
上执行该函数,但它目前存在于类之外,所以它看不到它。