php - Adding vertical text into existing pdf

133

I am trying to modify an existing pdf, adding datas into it using FPDI and FPDF. So far everything is fine. The only thing I am stuck at is inserting vertical text into the pdf.

Tried searching online, but non of the codes really worked.

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; 

I tried this, but this doesnt work together with FPDI, i.e I can generate new pdfs with verical or angled texts. But what I am trying to do is to insert vertical text into the already exisitng pdf. Unfortunately, FPDF doesnt allow to set source file. FPDI does, but this code isnt working together with FPDI somehow.

22

Answer

Solution:

The quoted code is extracted from this extension. The extension will work with FPDI as with FPDF by changing its extending class name as described here.

So the extension class definition will become e.g.:

class PDF_Rotate extends FPDI
{
    ...
}

And you can still use the methods of FPDI:

$pdf = new PDF_Rotate();
$pdf->AddPage();
$pageCount = $pdf->setSourceFile("template.pdf");
$tplIdx = $pdf->importPage(1);
$pdf->useTemplate($tplIdx);
$pdf->Rotate(100, 60, 90);
$pdf->Text(100, 60, 'Hello!');
$pdf->Rotate(0);
$pdf->Output();

People are also looking for solutions to the problem: More elegant way of looping through array and aggregating result in PHP

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.