Jump to content

Rotating text in pdf using php


smith.james0

Recommended Posts

It the moment I use this code to to write the week number on top of a pdf template.

[code]require('../pdf/fpdi.php');

$week = $_POST[week];


$pdf= new fpdi();

$pagecount = $pdf->setSourceFile("weelkytargets.pdf");
$tplidx = $pdf->ImportPage(1);

$pdf->addPage();
$pdf->useTemplate($tplidx,10,10);


        $pdf->SetFont('Arial','',18);
        $pdf->SetTextColor(0);
        $pdf->SetXY(142,33);
        $pdf->write(10,"$week");
        

$pdf->Output("newpdf.pdf","I");
$pdf->closeParsers();[/code]

This works ok when the document is portrate. I now have a document which is landscape, when using the code above it cuts of half of the page. So i need to either make the pdf i generate on the fly landscape or rotate the template and rotate the week number. I have tried to find how you make a landscape pdf but i haven't found anything. So i have tried rotating the text using this code.
[code]require('../pdf/rotation.php');

class PDF extends PDF_Rotate
{
function RotatedText($x,$y,$txt,$angle)
{
    //Text rotated around its origin
    $this->Rotate($angle,$x,$y);
    $this->Text($x,$y,$txt);
    $this->Rotate(0);
}

function RotatedImage($file,$x,$y,$w,$h,$angle)
{
    //Image rotated around its upper-left corner
    $this->Rotate($angle,$x,$y);
    $this->Image($file,$x,$y,$w,$h);
    $this->Rotate(0);
}
}

$pdf=new PDF();
$pdf->AddPage();
$pdf->SetFont('Arial','',20);
$pdf->RotatedText(100,60,'Hello!',45);
$pdf->Output();
[/code]
This works great but i carn't get it to work with the template, can anyone help?

Thanks James
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.