略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: PDF_rect

2024-05-07

PDF_rect

(PHP 4, PECL pdflib >= 1.0.0)

PDF_rectDraw rectangle

说明

PDF_rect ( resource $p , float $x , float $y , float $width , float $height ) : bool

Draws a rectangle. 成功时返回 TRUE, 或者在失败时返回 FALSE

add a note add a note

User Contributed Notes 4 notes

up
1
tobias at midas dot se
17 years ago
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);
}
?>
up
0
stuart at horuskol dot co dot uk
12 years ago
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.
up
-1
ragnar at deulos dot com
13 years ago
Be sure of adding a pdf_stroke(resource_pdf) after the pdf_rect function or will take an error in the PDFlib.
up
-4
nick
9 years ago
In php5 a rectangle with some text in is made like this.

<?php
$p
->rect(55,520,400,20);
$p->stroke();

$font = $p->load_font("Helvetica", "winansi", "");
$p->setfont($font, 14.0);
$p->set_text_pos(200, 525);
$p->show("Some text");

?>

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

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