超越PHP PHP动态 | 经典文章 | CLASS | 相关下载 | 常见问题 | FORUM | WIKI | 在线手册
Site search:    
<cpdf_place_inline_imagecpdf_restore>
Last updated: Fri, 22 Jun 2007

cpdf_rect

(PHP 3>= 3.0.8, PHP 4 , PHP 5)

cpdf_rect -- Draw a rectangle

Description

bool cpdf_rect ( int pdf_document, float x-coor, float y-coor, float width, float height [, int mode])

The cpdf_rect() function draws a rectangle with its lower left corner at point (x-coor, y-coor). This width is set to width. This height is set to height. 如果成功则返回 TRUE,失败则返回 FALSE

可选参数 mode 决定单元的长度。如果为 0 或被省略则使用该页指定的默认单元。否则坐标忽略当前单元而使用 postscript 的点来度量。

例子 1. Drawing a rectangle

<?php

$cpdf
= cpdf_open(0);
cpdf_page_init($cpdf, 1, 0, 595, 842, 1.0);

// set the fill color to red
cpdf_setrgbcolor($cpdf, 1, 0, 0);

// draw a (180 * 100) rectangle
cpdf_rect($cpdf, 645, 400, 180, 100);

// fill the rectangle
cpdf_fill($cpdf);

cpdf_finalize($cpdf);
Header("Content-type: application/pdf");
cpdf_output_buffer($cpdf);
cpdf_close($cpdf);

?>




add a note add a note User Contributed Notes
cpdf_rect
mikkel@hostpartner.dk
08-Sep-2002 08:29
To draw a rectangle, remember to set the fill color using the function cpdf_setrgbcolor(int pdf document, float red color, float green color, float blue color); before calling the cpdf_rect() function.

After calling the cpdf_rect() function, call the cpdf_fill(int pdf document), to fill the rectangle.

Example:

<?php
$cpdf = cpdf_open(0);
cpdf_page_init($cpdf, 1, 0, 595, 842, 1.0);

// Set the fill color (grey)
cpdf_setrgbcolor($cpdf, 0.9, 0.9, 0.9);

// Draw a rectangle (x-coor 645, y-coor 400, height 180, width 180)
cpdf_rect($cpdf, 645, 400, 180, 180);

// Fill the rectangle
cpdf_fill($cpdf);

cpdf_finalize($cpdf);
Header("Content-type: application/pdf");
cpdf_output_buffer($cpdf);
cpdf_close($cpdf);
?>

Notice that the color set with the cpdf_setrgbcolor(), as mentioned above, is used until another color is applied to the document.

<cpdf_place_inline_imagecpdf_restore>
 Last updated: Fri, 22 Jun 2007
view source | feedback | send page | sitemap | aboutus   
Copyright ® 2002-2003 PHPE.NET. All rights reserved
Last updated:2002-11-22