Lasso Soft Inc. > Home

[ pdf_color ]


[PDF_Color] is a type which can be used to instantiate color objects in any of the [PDF_...] types or methods which accept a -Color parameter. Also [PDF_Color] objects may be used to set colors in [PDF_...] graphics and drawing types through the ->SetColor method, but not for the [PDF_Font] type where instead ->SetColor requires a string hexadecimal value.

The -Color parameter must be one of Gray, RGB, or CMYK.

If Gray is specified, a decimal value ranging from 0 to 1.0 specifies a color intensity value.

If RGB is specified, three decimal values ranging from 0 to 1.0 specify red, green and blue values, respectively.

If CMYK is specified, four decimal values ranging from 0 to 1.0 specify cyan, magenta, yellow, and black values, respectively. The type can be spelled as either 'Gray' or 'Grey'.

When setting the color for a drawing or graphics object, the [PDF_Doc->SetColor] method requires two parameters. The first parameter is a string representing the type of drawing action, either 'Stroke', 'Fill' or 'Both'. The second parameter is either a [PDF_Color] object or the parameters normally used when instantiating a [PDF_Color] object.

  • Syntax
  • Methods
  • Traits
pdf_color('grey', Decimal Value)
pdf_color('rgb', Decimal Value, Decimal Value, Decimal Value)
pdf_color('cmyk', Decimal Value, Decimal Value, Decimal Value, Decimal Value)
Has methods:
  • pdf_color->oncreate(rgb::string, r::decimal, g::decimal, b::decimal)
  • pdf_color->oncreate(cymk::string, c::decimal, m::decimal, y::decimal, k::decimal)
  • pdf_color->oncreate(gray::string, intensity::decimal)
  • pdf_color->oncreate(spot::string, name::string, tint::decimal, color::pdf_color)
  • pdf_color->jcolor()
  • pdf_color->jcolor=(jcolor)
Has traits:
  • Beginner

To set colors within a PDF:

Use the [PDF_Color] type. The following examples demonstrate the proper techniques to set colors.


// instantiate two pdf_color objects, blue and red
local(blue) = pdf_color('rgb', 0.0, 0.0, 1.0)
local(red) = pdf_color('cmyk', 0.0, 1.0, 1.0, 0.0)

// instantiate myfont using blue
local(myfont) = pdf_font(
	-face   = 'Helvetica',
	-size   = 14,
	-color	= #blue)

// instantiate mypdf
local(mypdf) = pdf_doc(

// instantiate text using myfont
local(text) = pdf_text(
	'My first PDF.',

// add text

// set the color for subsequent drawing objects
#mypdf->setcolor('Stroke', #red)
// draw a diagonal line with width of 5.0 points...
// in a Cartesian coordinate system where the origin [0,0] is the lower left corner.
#mypdf->line(32, 32, 300, 300)

#mypdf = bytes(#mypdf)
file_serve(#mypdf, -file='mypdf.pdf', -type='Content-Type: application/pdf')


A PDF file is served to the web browser containing a paragraph of blue text, "My first PDF." and a red line drawn from the lower left corner toward the upper right at 45 degrees.

Recent Comments

No Comments found

Please note that periodically LassoSoft will go through the notes and may incorporate information from them into the documentation. Any submission here gives LassoSoft a non-exclusive license and will be made available in various formats to the Lasso community.

LassoSoft Inc. > Home



©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft