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.

8 Text and Table Formatting<br />

8.1 Placing and Fitting Textlines<br />

The function fit_textline( ) for placing a single line of text on a page offers a wealth of<br />

formatting options. The most important options will be discussed in this section using<br />

some common application examples. A complete description of these options can be<br />

found in the <strong>PDFlib</strong> API Reference. Most options for fit_textline( ) are identical to those of<br />

fit_image( ). Therefore we will only use text-related examples here; it is recommended to<br />

take a look at the examples in Section 7.3, »Placing Images and imported PDF Pages«,<br />

page 192, for an introduction to image formatting.<br />

The examples below demonstrate only the relevant call of fit_textline( ), assuming<br />

that the required font has already been loaded and set in the desired font size.<br />

fit_textline( ) uses a hypothetical text box to determine the positioning of the text:<br />

the width of the text box is identical to the width of the text, and the box height is identical<br />

to the height of capital letters in the font. The text box can be modified by the<br />

matchbox option which defines the text box.<br />

In the examples below, the coordinates of the reference point are supplied as x, y parameters<br />

of fit_textline( ). The fitbox for text lines is the area where text will be placed. It<br />

is defined as the rectangular area specified with the x, y parameters of fit_textline( ) and<br />

appropriate options (boxsize, position, rotate). The fitbox can be reduced to the left/right<br />

or top/bottom with the margin option.<br />

Cookbook Code samples regarding text output issues can be found in the text_output category of the<br />

<strong>PDFlib</strong> Cookbook.<br />

8.1.1 Simple Textline Placement<br />

Positioning text at the reference point. By default, the text will be placed with the lower<br />

left corner at the reference point. However, in this example we want to place the text<br />

with the bottom centered at the reference point. The following code fragment places<br />

the text box with the bottom centered at the reference point (30, 20).<br />

p.fit_textline(text, 30, 20, "position={center bottom}");<br />

Figure 8.1 illustrates centered text placement. Similarly, you can use the position option<br />

with another combination of the keywords left, right, center, top, and bottom to place<br />

text at the reference point.<br />

Fig. 8.1<br />

Centered text<br />

y<br />

Kraxi<br />

y<br />

Kraxi<br />

Fig. 8.2<br />

Simple text with<br />

orientation west<br />

x<br />

x<br />

8.1 Placing and Fitting Textlines 199

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

Saved successfully!

Ooh no, something went wrong!