我有一个脚本可以从数据库 blob 构建多页 pdf。这个pdf文件可以工作并输出良好的电流,但我需要在每页的左侧添加一条垂直的文本行。我已经设法让它适用于某些 pdf 文件,但对于某些 pdf 文件,我收到损坏的文件错误。有谁有不同的方法来添加垂直文本我可以尝试使用 fpdf/fpdi。
这是我到目前为止所拥有的:
function buildBSIPDF($filename){
global $supplier;
$pdf = new FPDI();
$i = 1;
$pagecount = $pdf->setSourceFile($filename);
//create text to append
$sideline = "Some text here";
while($i <= $pagecount){
//$pdf->setSourceFile($filename);
// import page 1
$tplIdx = $pdf->importPage($i);
//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
//$s = $pdf->getTemplatesize($tplidx);
$pdf->AddPage();
$pdf->useTemplate($tplIdx);
// now write some text above the imported page
$pdf->SetFont('Arial', '', '12');
$pdf->SetTextColor(0,0,0);
//set position in pdf document
$pdf->SetXY(20, 20);
//first parameter defines the line height
$pdf->RotatedText(5,250,$sideline,90);
$i++;
}
$pdf->Output($filename, 'F');
}
尝试这个 :
class PDF extends FPDF {
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));
}
}
}
$pdf=new PDF();
$pdf->AddPage();
$pdf->SetFont('Arial','',10);
$this->Rotate(10);
$pdf->Write(20,'this text is crooked');
$this->Rotate(0);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)