pdf_rect

(PHP 3 >= 3.0.6, PHP 4, PECL)

pdf_rect -- Draws a rectangle

Description

bool pdf_rect ( resource pdfdoc, float x, float y, float width, float height )

Draw a (width * height) rectangle at lower left (x, y). 如果成功则返回 TRUE,失败则返回 FALSE


add a note add a note User Contributed Notes
stuart at horuskol dot co dot uk
09-Jun-2006 05:14
This section of the manual is really sparse, and there don't seem to be any tutorials out there that go beyond adding a single line of text, so I found this piece of information out by trial and error.

The function only specifies that you want a rectangle at those co-ordinates, and must be followed by a stroke command:

  pdf_rect($pdf, 100, 100, 50, 50);
  pdf_stroke($pdf);

This completes the process of placing the rectangle on the page.
ragnar at deulos dot com
05-Oct-2005 02:09
Be sure of adding a pdf_stroke(resource_pdf) after the pdf_rect function or will take an error in the PDFlib.
tobias at midas dot se
16-May-2002 05:31
Round rectangles

My function to create rectangles width round corners:

<?php
function pdf_roundrect($pdfobj, $xpos, $ypos, $xsize, $ysize, $radius)
{
 
$ypos = $ypos+$ysize;
 
pdf_moveto($pdfobj, $xpos, $ypos-$radius);
 
pdf_lineto($pdfobj, $xpos, $ypos-$ysize+$radius);
 
pdf_arc($pdfobj, $xpos+$radius, $ypos-$ysize+$radius, $radius, 180, 270);
 
pdf_lineto($pdfobj, $xpos+$xsize-$radius, $ypos-$ysize);
 
pdf_arc($pdfobj, $xpos+$xsize-$radius, $ypos-$ysize+$radius, $radius, 270, 360);
 
pdf_lineto($pdfobj, $xpos+$xsize, $ypos-$radius);
 
pdf_arc($pdfobj, $xpos+$xsize-$radius, $ypos-$radius, $radius,0,90);
 
pdf_lineto($pdfobj, $xpos+$radius, $ypos);
 
pdf_arc($pdfobj, $xpos+$radius, $ypos-$radius, $radius,90,180);
}
?>
02-Aug-2001 08:26
This will draw a simple rectangle...
...with a few extras.

<?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;

?>

Thanx to:
http://www.dynamicwebpages.de/50.tutorials.php?dwp_tutorialID=11
Great german (!!!) tutorial