| 595, 842);
$arial = PDF_findfont($pdf, "Arial", "host", 1);
PDF_setfont($pdf, $arial, 12);
// 设定直线的颜色
PDF_setcolor($pdf, "stroke", "rgb", 0, 0, 0);
// 在左上角放置一个Logo标识
$image = PDF_open_image_file($pdf, "jpeg", "logo.jpg");
PDF_place_image($pdf, $image, 50, 785, 0.5);
// 在Logo标识下画出直线
PDF_moveto($pdf, 20, 780);
PDF_lineto($pdf, 575, 780);
PDF_stroke($pdf);
// 在页面底部画出另外一条直线
PDF_moveto($pdf, 20,50);
PDF_lineto($pdf, 575, 50);
PDF_stroke($pdf);
// 输出一些文字
PDF_show_xy($pdf, "Meng's Corporation", 200, 35);
PDF_end_page($pdf);
PDF_close($pdf);
?>
从上面的例子可以看出,要画一条直线,只需要三个函数即可:PDF_moveto(), PDF_lineto() 和 PDF_stroke()。上面的例子是先用PDF_moveto($pdf, 20, 780)函数把光标移动到坐标(20,780),然后用PDF_lineto($pdf, 575, 780)函数定义直线的另外一个点的坐标(575,780),最后用PDF_stroke($pdf)画出线。设定颜色的函数PDF_setcolor($pdf, "stroke", "rgb", 0, 0, 0)有好几个参数,其中的颜色填充模式有stroke、fill、both三种选项,颜色可以是RGB或CMYK配色方案的颜色值。值得注意的是:PDF_setcolor()函数中使用的值是颜色的百分比,也就是说是该颜色的亮度,比如:如果想设为红色(RGB:255,0,0),你可以这样写:PDF_setcolor($pdf, "stroke", "rgb", 1, 0, 0),如果想设为黄色,可以这样:PDF_setcolor($pdf, "stroke", "rgb", 1, 1, 0)。
要想画带填充色的长方形和圆形,可以使用下面的方法:
//设定填充颜色
PDF_setcolor($pdf, "fill", "rgb", 1, 1, 0);
// 设定边框线的颜色
PDF_setcolor($pdf, "stroke", "rgb", 0, 0, 0);
// 画矩形,后面的四个参数分别是左下角的坐标X、Y和宽度、高度
PDF_rect($pdf, 50, 500, 200, 300);
PDF_fill_stroke($pdf);
PDF_setcolor($pdf, "fill", "rgb", 0, 1, 0);
PDF_setcolor($pdf, "stroke", "rgb", 0, 0, 1);
// 画出圆,参数分别是圆心坐标和圆的半径
PDF_circle($pdf, 400, 600, 10
上一页 [1] [2] [3] [4] [5] [6] 下一页 |