17.05.2014 Views

PDFlib 8 Windows COM/.NET Tutorial

PDFlib 8 Windows COM/.NET Tutorial

PDFlib 8 Windows COM/.NET Tutorial

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

3.2 Page Descriptions<br />

3.2.1 Coordinate Systems<br />

PDF’s default coordinate system is used within <strong>PDFlib</strong>. The default coordinate system<br />

(or default user space) has the origin in the lower left corner of the page, and uses the<br />

DTP point as unit:<br />

1 pt = 1/72 inch = 25.4/72 mm = 0.3528 mm<br />

The first coordinate increases to the right, the second coordinate increases upwards.<br />

<strong>PDFlib</strong> client programs may change the default user space by rotating, scaling, translating,<br />

or skewing, resulting in new user coordinates. The respective functions for these<br />

transformations are rotate( ), scale( ), translate( ), and skew( ). If the coordinate system has<br />

been transformed, all coordinates in graphics and text functions must be supplied according<br />

to the new coordinate system. The coordinate system is reset to the default coordinate<br />

system at the start of each page.<br />

Using metric coordinates. Metric coordinates can easily be used by scaling the coordinate<br />

system. The scaling factor is derived from the definition of the DTP point given<br />

above:<br />

p.scale(28.3465, 28.3465);<br />

After this call <strong>PDFlib</strong> will interpret all coordinates (except for interactive features, see<br />

below) in centimeters since 72/2.54 = 28.3465.<br />

As a related feature, the userunit option in begin/end_page_ext( ) (PDF 1.6) can be specified<br />

to supply a scaling factor for the whole page. Note that user units will only affect final<br />

page display in Acrobat, but not any coordinate scaling in <strong>PDFlib</strong>.<br />

Cookbook A full code sample can be found in the Cookbook topic general/metric_topdown_coordinates.<br />

Coordinates for interactive elements. PDF always expects coordinates for interactive<br />

functions, such as the rectangle coordinates for creating text annotations, links, and file<br />

annotations in the default coordinate system, and not in the (possibly transformed)<br />

user coordinate system. Since this is very cumbersome <strong>PDFlib</strong> offers automatic conversion<br />

of user coordinates to the format expected by PDF. This automatic conversion is activated<br />

by setting the usercoordinates parameter to true:<br />

p.set_parameter("usercoordinates", "true");<br />

Since PDF supports only link and field rectangles with edges parallel to the page edges,<br />

the supplied rectangles must be modified when the coordinate system has been transformed<br />

by scaling, rotating, translating, or skewing it. In this case <strong>PDFlib</strong> will calculate<br />

the smallest enclosing rectangle with edges parallel to the page edges, transform it to<br />

default coordinates, and use the resulting values instead of the supplied coordinates.<br />

The overall effect is that you can use the same coordinate systems for both page content<br />

and interactive elements when the usercoordinates parameter has been set to true.<br />

68 Chapter 3: Creating PDF Documents (Edition for <strong>COM</strong>, .<strong>NET</strong>, and REALbasic)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!