PhpDig.net

What is PhpDig?
PhpDig is a PHP MySQL based
Web Spider & Search Engine.




pdf_setcolor

Name

pdf_setcolor — Set the current color space and color.

Synopsis

bool pdf_setcolor(pdf, mode, colorspace, c1[, c2][, c3][, c4]);
resource pdf: PDF object identifier
string mode: Color mode
string colorspace: Color space type
double c1: Color one
double c2 (optional): Color two
double c3 (optional): Color three
double c4 (optional): Color four

Returns

Always TRUE

Description

A relatively complex function but once the principles have been grasped, it's useful to know. pdf_setcolor() controls the behaviour and type of nearly any aspect of the document involving color. Depending on what the value of colorspace is set to, other parameters may or may not be required.

type should be stroke, fill or both and controls which which parts of an object is colored when using pdf_stroke() , pdf_fill() , or pdf_fill_stroke() .

colorspace can be gray, rgb, cmyk, spot or pattern. If colorspace is gray then c1 specifies a gray value. If colorspace is rgb then c1 , c2 and c3 specify red,green,and blue values. If colorspace is cmyk then c1 , c2 , c3 and c4 specify cyan,magenta,yellow,and black values. If colorspace is spot then c1 specifies a spot color handle returned by pdf_makespotcolor() and c2 specifies a tint value between 0 and 1. If colorspace is pattern then c1 specifies a pattern handle returned by pdf_begin_pattern() .

Version

Since version 4.0.5

Example

Example 969. Demonstrate function parameters

<?php

// create new document
$pdf = pdf_new();
pdf_open_file($pdf);
pdf_begin_page($pdf, 500, 700);

// set stroke
// the last value is not used
pdf_setcolor($pdf, "stroke", "rgb", 0.9, 0.1, 0.1, 0.0);
pdf_rect($pdf, 30, 640, 180, 30);
pdf_stroke($pdf);

// set fill
pdf_setcolor($pdf, "fill", "rgb", 0.1, 0.9, 0.1, 0.0);
pdf_rect($pdf, 30, 600, 180, 30);
pdf_fill($pdf);

// set stroke again
// note color space of stroke
pdf_setcolor($pdf, "fill", "cmyk", 0.7, 0.3, 0.1, 0.0);
pdf_rect($pdf, 30, 560, 180, 30);
pdf_fill_stroke($pdf);

// set stroke and fill color
pdf_setcolor($pdf, "both", "cmyk", 0.7, 0.3, 0.1, 0.0);
pdf_rect($pdf, 30, 520, 180, 30);
pdf_fill_stroke($pdf);

// set gray fill
pdf_setcolor($pdf, "fill", "gray", 0.8, 0.0, 0.0, 0.0);
pdf_rect($pdf, 30, 480, 180, 30);
pdf_fill($pdf);

pdf_end_page($pdf);
pdf_close($pdf);

// output document
$data = pdf_get_buffer($pdf);
header("Content-type: application/pdf");
header("Content-disposition: inline; filename=test.pdf");
header("Content-length: " . strlen($data));
echo $data;
?>



PHP Functions Essential Reference. Copyright © 2002 by New Riders Publishing (Authors: Zak Greant, Graeme Merrall, Torben Wilson, Brett Michlitsch). This material may be distributed only subject to the terms and conditions set forth in the Open Publication License, v1.0 or later (the latest version is presently available at http://www.opencontent.org/openpub/). The authors of this book have elected not to choose any options under the OPL. This online book was obtained from http://www.fooassociates.com/phpfer/ and is designed to provide information about the PHP programming language, focusing on PHP version 4.0.4 for the most part. The information is provided on an as-is basis, and no warranty or fitness is implied. All persons and entities shall have neither liability nor responsibility to any person or entity with respect to any loss or damage arising from the information contained in this book.

Powered by: vBulletin Version 3.0.7
Copyright ©2000 - 2005, Jelsoft Enterprises Ltd.
Copyright © 2001 - 2005, ThinkDing LLC. All Rights Reserved.