Hi,
Does anyone know how to rotate text by 90degrees using FPDF.org?
Please help me!!
Hi,
Does anyone know how to rotate text by 90degrees using FPDF.org?
Please help me!!
try there help section.
edraynham,
try this.
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);
$pdf->Write(20,this text is straight);
$this->Rotate(10);
$pdf->Write(20,this text is crooked);
$this->Rotate(0);
$pdf->Write(20,this text is straight again);
$pdf->Output();
I didn't write the function, I found it somewhere and it's working just fine for me. Let me know whether it helps.
This is a typical "register by one post":
Of course that works!
If you still alive take a frozen margarita to your salute...
I.-
NomikOS;10951930 wrote:This is a typical "register by one post":
Of course that works!
If you still alive take a frozen margarita to your salute...
I.-
Salud! Glad to have been of assistance.
Guys, wanted to give a heads-up: you MUST call Rotate(0) at the end of every page to output a matching 'Q' command, otherwise you end up with a broken PDF (which is unnoticeable in OS X Preview.app and also unnoticeable for single-page document, but as soon as you have 2+ pages, Adobe Reader starts complaining).
The example gets this right, but it's not otherwise obvious from the code.
Basically 'q' and 'Q' must be balanced in PDFs (those are “push state” and “pop state” commands). Just spent 2 hours to find this out.
Many thanks to ergot, for the great Rotate function. I had to make a few corrections to make it work for me, and I'll detail those here for others who may be having trouble -
Thanks again!
Sorry, but I don't see an "Edit" link -
Also, remember that your X and Y will be reversed when using Rotate(). Rather obvious, but I wasted an hour trying to place text near the right margin and kept having it disappear.
Didn't work for me, I applied the changes suggested by compusolver, to no avail. At last I got it working. I paste the fixed code:
class PDF extends FPDF {
public $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));
}
}
}
$pdf=new PDF();
$pdf->AddPage();
$pdf->SetFont('Arial','',10);
$pdf->Write(20,'this text is straight');
$pdf->Rotate(10);
$pdf->Write(20,'this text is crooked');
$pdf->Rotate(0);
$pdf->Write(20,'this text is straight again');
$pdf->Output();
Hi, I used the exactly code, it work in localhost, but when I upload into server. it appear
Fatal error: Call to undefined method FPDF::RotatedText()
My server is running in window O/S
So, install the FPDF class/software? http://www.fpdf.org/
Also, take a look here for "how to start a new discussion" ... this one was over 4 years old
https://board.phpbuilder.com/d/10402054-tips-and-tricks-for-the-new-spring-2018-forum-software