Draw Function

Modified on Wed, Feb 14, 2018 at 3:59 PM

DRAW Command - Blocks

 ‘Draw’ enables drawing entities inside or outside the block’s boundary. The draw command can be applied to all block types; it is, however, most useful in conjunction with the shrink commands (shrinkleft, shrinkright and shrinkcenter) as the entity will be drawn based on the location of one of its corners or center. This, of course, implies that the preferred block type is textflow.

Currently, the supported entities are:

Line – line

Rectangle – rect

Path - path

Circle – circle

Text – text

Text Flow – textflow

Image – image (covers image, graphics and pdf)

Background – background (special case see below for details)

Syntax

The value of the ‘draw’ command must start with the Entity name followed by a number of attributes (key=value) separated by spaces. If a value contains a space then it should be surrounded by double-quotes.

Example:

line x1=10 x2=10 x2=200 y2=200 ref=”bottom left”

If ref is skipped then it defaults to bottom left corner of the block.


 

Attributes (see below for background entity)   

Attribute
Definition
Entity
x1 y1
horizontal and vertical distance away from the reference corner
All entities
x2 y2
horizontal and vertical distance away from the reference corner
All entities except circle and path
radius
Radius of a circle, x1,y1 are its center
circle
xsep ysep
Separator x and y coordinates for subsequent entities
text image textflow
xrep yrep
Separator x and y coordinates for repeat entities
All entities
linewidth
Width of line, rectangle and circle
line rect circle
repeat
No of times the entity is repeated
All entities
fillcolor
Fill color of entity
rect circle
strokecolor
Stroke color of entity
line rect circle
text
Text to be printed.
text textflow
image
Path to image, graphics or pdf
image
path
X Y coordinates of connected points separated by four semi-colons (;;;;). Equations are allowed.
path
showborder
Show border of drawn block containing the text or image
text image textflow
Rotate
Rotate text or image. Value entered in degrees.
All entities
scale
Scale text or image (default 1)
All entities
orientate
North, West, South or East
text image textflow
fitmethod
For text and image: auto, meet, entire or clip. For textflow: nofit, auto or clip
text image textflow
position
Can be entered using left top or center. Numbers also are accepted 0 being left or bottom, 100 right or top
text image
verticalalign
Vertical alignment for textflow. Top, bottom, center or justify.
textflow

 


 

Attribute Values

Attribute
Value
x1, y1, x2, y2, radius, xsep, ysep, xrep, yrep
Any negative or positive number in pdf units (inches x 72). Equations are parsed, so x1=45*3 is valid. Useful when using the::Length command of a block to determine the number of characters it contains. More details below.
linewidth
Positive number
fillcolor, strokecolor
Valid pdf color. Example: fillcolor=”cmyk 0 1 1 0”
rotate
Positive or negative degrees
scale
Positive number from 0 up
orientate
north, west, south or east
fitmethod
Auto, meet, entire or clip for text and image. Nofit, auto or clip for textflow
position
left top right bottom or center. Numbers also are accepted 0 being left or bottom, 100 right or top
verticalalign
Vertical alignment for textflow. Top, bottom, center or justify.
reverse
reverse=true causes the entity be drawn before the block.

 

 

 

NOTES

  • {BlockName::length} is a special keyword that returns the length of the block - without html tags or pdflib command tags (within angle brackets<>)
  • {BlockName::lengthall} returns the length of all characters including the ones inside the angle brackets.
  • In x1, y1, x2, y2 and radius, {BlockName::length} can be used to calculate distances. For example x1=”{BlockName::length}*5” is valid and returns the number of characters of BlockName block multiplied by 5. Allowed operations are *, /, +, - and ^.
  • {BlockName::length} inside any text or paragraph will print the number of characters and not the text. It can also be used inside if statements of the paragraph command for comparison.
  • Text attribute when used with textflow entity supports all PDFLib embedded commands.
  • As an exception to the rule, same block can be referenced inside its draw command.
  • The coordinate translation is controlled by two attributes xsep and ysep. By default, their values are 0 meaning the multiple attributes will show one on top of the other.
  • Text (for text and textflow entities) and image attributes recognizes ;;;; to separate subsequent values. ;;;; separator is also affected by the repeatattribute. Repeat repeats all entities (;;;; separated) defined number of times.
  • Text and image attributes recognize a special keyword :#: that will be replaced by a sequential number starting from 1 up to the number defined in the repeat attribute.  
  • Not setting x2 and y2 or setting them to 0 will cause the images be placed without scaling.
  • llx, lly, urx, ury, w, and h are recognized inside the value of attributes x1, y1, x2, y2, radius, linewidth, xsep, ysep, xrep, yrep and repeat. All dimensions are in PDF units (inches x 72)
  • llx, lly     lower left horizontal and vertical dimensions of the block
  • urx, ury                upper right horizontal and vertical dimensions of the block
  • w, h       Width and Height of the block
  • All entities translate the user coordinate system to the reference point except ‘path’. The path entity translates the user coordinate system to x1, y1 instead. Each point in the value of the path attribute is relative to the point before which makes it easier to enter the data.

 

 

EXAMPLES

Example1: image

image ref="center" x1=10 y1=-100 x2="{Company Name::length}*10" y2=(-20*5)*1.5 fitmethod=auto position=50 image="~/Storage/1/1/3/Assets/Images/tiger.jpg"

Places an image to the right and below the center of the block by 10,-100 pdf units. The width of the block containing the image is the company name length multiplied by 10 and subtracted by 10 (x1) and the height is 150-100 = 50 pdf units. The new block reference point is always the left bottom corner.

 

Example2: rect

rect ref="right bottom" x1=10 y1=20 x2=200 y2=40 linewidth=2 strokecolor="cmyk 1 0 1 0" fillcolor="cmyk 0 1 1 0"

The above draws a red rectangle with green borders. Reference point is the right bottom corner of the block.

 



Example 3: textflow

textflow ref="left bottom" x1=-2 y1=2 x2=200 y2=40 text="{Name}" fillcolor="cmyk 0 1 1 0"

Prints block contents in red shifted -2 horizontally and +2 vertically as shown below




Example 4: image

image ref="right bottom" x1=10 y1=-50 x2="150" y2=-150  position=50 image="~/Storage/1/1/3/Assets/Images/leopard.jpg"

Image moves depending on the length of the block (shrinkleft has been used in the status command of the block).


Example 5: image (multiple images with separators)

image ref="right bottom" x1=10 y1=-50 x2="150" y2=-100  position=50 xsep=20 ysep=-20 image="~/Storage/1/1/3/Assets/Images/leopard.jpg;;;;~/Storage/1/1/3/Assets/Images/leopard.jpg;;;;~/Storage/1/1/3/Assets/Images/leopard.jpg" 



Example 6: textflow (multiple occurrences)

textflow ref="left bottom" x1=15 y1=-15 x2=200 y2=40 xsep=10 ysep=-10 linewidth=2 text="<fillcolor={cmyk 0 1 1 0}>{Name} 1;;;;<fillcolor={cmyk 1 0 1 0}>{Name} 2;;;;<fillcolor={cmyk 0 1 0 0}>{Name} 3;;;;<fillcolor={cmyk 1 1 0 0}>{Name} 4"



All PDFlib line commands are valid inside the text attribute of textflow entity. The above example shows the usage of switch colors <fillcolor={cmyk 0 1 1 0}>.

Draw attribute value can be placed without surrounding double-quotes if it has no spaces otherwise the value MUST be surrounded by double-quotes. Examples:

X1=10                                    valid

X1=”10”                                valid

X1=10*10                            valid

X1=10 * 10                          Invalid spaces between 10 and * and 10

X1=”10 * 10”                      valid

 

The fillcolor and strokecolor attributes of the draw command should also follow the same rule:

Fillcolor=”cmyk 1 0 1 0” and not fillcolor={cmyk 1 0 1 0}

One exception is when fillcolor is used within the text attribute of a textflow entity then the standard PDFlib syntax MUST be used:

text="<fillcolor={cmyk 0 1 1 0}>{Name}”

 

Example 7: textflow (repeat using index numbering)

textflow ref="left bottom" x1=25 y1=-25 x2=200 y2=40 xrep=5 yrep=-5 linewidth=2 text="<fillcolor={cmyk 0 1 1 0}>{Name} :#:" repeat=20

 

Example 9: image (moving icons)

image ref="right bottom" x1=10 y1=-2 x2=30 y2=30 xsep=40 image="{Logo1};;;;{Logo2};;;;{Logo3};;;;{Logo4};;;;{Logo5}"

{Logo1} to {Logo3} are blocks with checkbox commands returning path to image


Background

The background command is a special case where the block defined by x1, y1 and x2, y2 is filled with gradient fill. Reverse is recognized.

The background attributes consists of three parts each surrounded by square brackets []. Commas separate the parameters inside each part. The first parameter of the first part selects the clip type. The second parameter selects the entity: rect, circle, and ellipse. The second part is for the starting fill color. The third part is for actually creating the gradient fill. The first parameter is the type of gradient (radial or axial) followed by 4 parameter for second color, the last parameter is for optlist (defaults to empty string).

 

Example 1: background (apply background to block area)

background x1=llx y1=lly x2=urx y2=ury background="[clip, rect][fill, rgb, 0, 0, 0,0][axial,0.4, 0.5, 0.1, 0.0,]" reverse="true"

Example 2: background

background x1=100 y1=100 x2=200 y2=200 background="[clip, circle][fill, rgb, 0, 0, 0,0][axial,0.4, 0.5, 0.1, 0.0,]" reverse="true"

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article