PDFlib 8 Windows COM/.NET Tutorial
PDFlib 8 Windows COM/.NET Tutorial
PDFlib 8 Windows COM/.NET Tutorial
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Direct Paths. Using the path functions moveto( ), lineto( ), rect( ) etc. you can construct a<br />
direct path which will immediately be written to the current page or another content<br />
stream (e.g. a template or Type 3 glyph description). Immediately after constructing the<br />
path it must be processed with one of stroke ( ), fill( ), clip( ) and related functions. These<br />
functions will consume and delete the path. The only way to use a path multiply is with<br />
save( ) and restore( ).<br />
It is an error to construct a direct path without applying any of the above operations to<br />
it. <strong>PDFlib</strong>’s scoping system ensures that clients obey to this restriction. If you want to set<br />
any appearance properties (e.g. color, line width) of a path you must do so before starting<br />
any drawing operations. These rules can be summarized as »don’t change the appearance<br />
within a path description«.<br />
Merely constructing a path doesn’t result in anything showing up on the page; you<br />
must either fill or stroke the path in order to get visible results:<br />
p.setcolor("stroke", "rgb", 1, 0, 0, 0);<br />
p.moveto(100, 100);<br />
p.lineto(200, 100);<br />
p.stroke();<br />
Most graphics functions make use of the concept of a current point, which can be<br />
thought of as the location of the pen used for drawing.<br />
Cookbook A full code sample can be found in the Cookbook topic graphics/starter_graphics.<br />
Path objects. Path objects are more convenient and powerful alternative to direct<br />
paths. Path objects encapsulate all drawing operations for constructing the path. Path<br />
objects can be created with add_path_point( ) or extracted from an image file which includes<br />
an image clipping path (see below). add_path_point( ) supports several convenience<br />
options to facilitate path construction. Once a path object has been created it can<br />
be used for different purposes:<br />
> The path object can be used on the page description with draw_path( ), i.e. filled,<br />
stroked, or used as a clipping path.<br />
> Path objects can be used as wrap shapes for Textflow: the text will be formatted so<br />
that it wraps inside or outside of an arbitrary shape (see Section 8.2.10, »Wrapping<br />
Text around Paths and Images«, page 223).<br />
> Text can also be placed on a path, i.e. the characters follow the lines and curves of the<br />
path (see Section 8.1.7, »Text on a Path«, page 205).<br />
> Path objects can be placed in table cells.<br />
Unlike direct paths, path objects can be used multiply until they are explicitly destroyed<br />
with delete_path( ). Information about a path can be retrieved with info_path( ).<br />
The following code fragment creates a simple path shape with a circle, strokes it at two<br />
different locations on the page, and finally deletes it:<br />
path = p.add_path_point( -1, 0, 100, "move", "");<br />
path = p.add_path_point(path, 200, 100, "control", "");<br />
path = p.add_path_point(path, 0, 100, "circular", "");<br />
p.draw_path(path, 0, 0, "stroke");<br />
p.draw_path(path, 400, 500, "stroke");<br />
p.delete_path(path);<br />
72 Chapter 3: Creating PDF Documents (Edition for <strong>COM</strong>, .<strong>NET</strong>, and REALbasic)