在PHP中使用fpdf/fpdi添加垂直文本 [英] Adding vertical text with fpdf/fpdi in php

查看:231
本文介绍了在PHP中使用fpdf/fpdi添加垂直文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个脚本,可以从数据库Blob构建多页pdf.该pdf可以正常工作并输出良好的电流,但是我需要在每页的左侧下方添加一条垂直的文字行.我设法使它适用于某些pdf,但对于某些我却得到了损坏的文件错误.有没有人有其他添加垂直文本的方式,我可以尝试使用fpdf/fpdi.

I have a script that builds up a multi page pdf from a database blob. This pdf works and outputs fine current but I need to add a vertical line of text down the left hand side of each page. I have managed to get this to work for some of the pdfs but for some I get a corrupted file error. Does anyone have a different way of adding vertical text I can try using fpdf/fpdi.

这是我到目前为止所拥有的:

This is what I have so far:

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); 

这篇关于在PHP中使用fpdf/fpdi添加垂直文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆