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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

for each cell containing a text line the actual width is calculated based on the column<br />

width or the text width (or the text height in case of rotated text). Then, the remaining<br />

table width is evenly distributed among the column widths which are still missing.<br />

8.3.4 Mixed Table Contents<br />

In the following sections we will create the sample table containing various kinds of<br />

contents as shown in Figure 8.36 step by step.<br />

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

As a prerequisite we need to load two fonts. We define the dimensions of the table’s fitbox<br />

in terms of the coordinates of the lower left and upper right corners and specify the<br />

widths of the three table columns. Then, we start a new page with A4 size:<br />

double llx = 100, lly = 500, urx = 360, ury = 600; // coordinates of the table<br />

int c1 = 50, c2 = 120, c3 = 90; // widths of the three table columns<br />

boldfont = p.load_font("Helvetica-Bold", "unicode", "");<br />

normalfont = p.load_font("Helvetica", "unicode", "");<br />

p.begin_page_ext(0, 0, "width=a4.width height=a4.height");<br />

Step 1: Adding the first cell. We start with the first cell of our table. The cell will be<br />

placed in the first column of the first row and will span three columns. The first column<br />

has a width of 50 points. The text line is centered vertically and horizontally, with a<br />

margin of 4 points from all borders. The following code fragment shows how to add the<br />

first cell:<br />

optlist = "fittextline={font=" + boldfont + " fontsize=12 position=center} " +<br />

"margin=4 colspan=3 colwidth=" + c1;<br />

tbl = p.add_table_cell(tbl, 1, 1, "Our Paper Plane Models", optlist);<br />

if (tbl == -1)<br />

throw new Exception("Error: " + p.get_errmsg());<br />

Step 2: Adding one cell spanning two columns. In the next step we add the cell containing<br />

the text line 1 Giant Wing. It will be placed in the first column of the second row<br />

and spans two columns. The first column has a width of 50 points. The row height is 14<br />

points. The text line is positioned on the top left, with a margin of 4 points from all borders.<br />

We use fontsize={capheight=6} to get a unique vertical text alignment as described<br />

in »Fine-tuning the vertical alignment of cell contents«, page 230.<br />

Since the Giant Wing heading cell doesn’t cover a complete row but only two of three<br />

columns it cannot be filled with color using on of the row-based shading options. We<br />

apply the Matchbox feature instead to fill the rectangle covered by the cell with a gray<br />

background color. (The Matchbox feature is discussed in detail in Section 8.4, »Matchboxes«,<br />

page 243.) The following code fragment demonstrates how to add the Giant Wing<br />

heading cell:<br />

optlist = "fittextline={position={left top} font=" + boldfont +<br />

" fontsize={capheight=6}} rowheight=14 colwidth=" + c1 +<br />

" margin=4 colspan=2 matchbox={fillcolor={gray .92}}";<br />

tbl = p.add_table_cell(tbl, 1, 2, "1<br />

Giant Wing", optlist);<br />

234 Chapter 8: Text and Table Formatting (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!