PHP : Function Reference : PDF Functions : PDF_rotate
Examples ( Source code ) » PDF_rotate
<?php
//Create & Open PDF-Object
$pdf = pdf_new();
pdf_open_file($pdf);
pdf_set_info($pdf, "Author","Bob Nijman");
pdf_set_info($pdf, "Title","www.nijman.de");
pdf_set_info($pdf, "Creator", "bob@nijman.de");
pdf_set_info($pdf, "Subject", "pdf-stuff");
pdf_begin_page($pdf, 200, 200);
// just a simple rectangle
pdf_setlinewidth($pdf, 5); //make the border of the rectangle a bit wider
pdf_rotate($pdf, 5); //rotate the coordinate system (NOT THE RECTANGLE !!!!!)
pdf_rect($pdf, 100, 100, 50, 50); //draw the rectangle
pdf_stroke($pdf); //stroke the path with the current color(not yet :-)) and line width
//note: the rect is not drawn untill we use pdf_stroke - try it out!!!
//close it up
pdf_end_page($pdf);
pdf_close($pdf);
$data = pdf_get_buffer($pdf);
header('Content-type: application/pdf');
header('Content-disposition: inline; filename=invoice.pdf');
header('Content-length: ' . strlen($data));
echo $data;
?>
bml137
When you rotate, remember that you are rotating the coordinate system. So if you are rotating 90 degrees with the origin at (0,0) (bottom-left corner on PDFs) in the clockwise direction, then the pivot appears to be on the top-left of the PDF. For instance, if you put a sheet of paper on the table in vertical position, then rotate it clockwise 90 degrees by pivoting from the bottom-left corner, the pivot (or origin) will now be in the top-left corner of the horizontal paper. As you can see, you now have room show text in the +x, -y directions, not +x, +y.
gman
Thanks for your help, this is a clean working example ...
<?php
$pdf = pdf_new();
pdf_open_file($pdf);
pdf_set_info($pdf,"Creator","images.php");
pdf_set_info($pdf,"Title","Horizontal and Vertical Example");
// Width of 612, and length of 792 make US Letter Size
// Dimensions are reversed for Landscape Mode
pdf_begin_page($pdf,792,612);
pdf_set_font($pdf, "Helvetica-Oblique", 18, "host");
pdf_show_xy($pdf, "This is horizontal text",50, 300);
pdf_rotate($pdf, 90); /* rotate coordinates */
pdf_show_xy($pdf,"vertical text",300, -400);
pdf_rotate($pdf, -90); /* rotate coordinates */;
pdf_show_xy($pdf, "This is horizontal text",50, 400);
pdf_end_page($pdf);
pdf_close($pdf);
$buf = pdf_get_buffer($pdf);
$len = strlen($buf);
Header("Content-type: application/pdf");
Header("Content-Length: $len");
Header("Content-Disposition: inline; filename=images.pdf");
echo $buf;
pdf_delete($pdf);
?>
|