略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: PDF_rotate

2024-11-15

PDF_rotate

(PHP 4, PECL pdflib >= 1.0.0)

PDF_rotateRotate coordinate system

说明

PDF_rotate ( resource $p , float $phi ) : bool

Rotates the coordinate system. 成功时返回 TRUE, 或者在失败时返回 FALSE

add a note add a note

User Contributed Notes 3 notes

up
0
notrub225 at yahoo dot com
11 years ago
Many of the functions used in the post below are deprecated. Here is the modern Object Oriented version that is almost the same line by line and uses the PDFlib() class:

<?php
    $pdf
= new PDFlib();
   
$pdf->begin_document("","");
   
$pdf->set_info("Creator","images.php");
   
$pdf->set_info("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_ext(792,612,'');

   
$font = $pdf->load_font("Helvetica-Oblique", "iso8859-1", "");
   
$pdf->setfont($font, 18);
   
$pdf->show_xy("This is horizontal text",50, 300);
   
$pdf->rotate(90); /* rotate coordinates */
   
$pdf->show_xy("vertical text",300, -400);
  
   
$pdf->rotate(-90); /* rotate coordinates */;
   
$pdf->show_xy("This is horizontal text",50, 400);

   
$pdf->end_page_ext("");
   
$pdf->end_document("");
   
$buf = $pdf->get_buffer();
   
$len = strlen($buf);
   
Header("Content-type: application/pdf");
   
Header("Content-Length: $len");
   
Header("Content-Disposition: inline; filename=images.pdf");
    echo
$buf;
   
$pdf->delete();
?>
up
0
bml137 at myglo dot net
16 years ago
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.
up
-3
gman at speakeasy dot net
16 years ago
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);
?>

官方地址:https://www.php.net/manual/en/function.pdf-rotate.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3