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.

11.5 Filling Blocks with PPS<br />

In order to fill Blocks with PPS you must first place the page containing the Blocks on<br />

the output page with the fit_pdi_page( ) function. After placing the page its Blocks can be<br />

filled with the fill_*block( ) functions.<br />

Simple example: add variable text to a template. Adding dynamic text to a PDF template<br />

is a very common task. The following code fragment opens a page in an input PDF<br />

document (the template or Block container), places it on the output page, and fills some<br />

variable text into a text Block called firstname:<br />

doc = p.open_pdi_document(filename, "");<br />

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

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

page = p.open_pdi_page(doc, pageno, "");<br />

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

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

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

/* Place the imported page */<br />

p.fit_pdi_page(page, 0.0, 0.0, "");<br />

/* Fill a single Block on the placed page */<br />

p.fill_textblock(page, "firstname", "Serge", "encoding=winansi");<br />

p.close_pdi_page(page);<br />

p.end_page_ext("");<br />

p.close_pdi_document(doc);<br />

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

Overriding Block properties. In certain situations the programmer wants to use only<br />

some of the properties provided in a Block definition, but override other properties<br />

with custom values. This can be useful in various situations:<br />

> Business logic may decide to enforce certain overrides.<br />

> The scaling factor for an image or PDF page will be calculated by the application instead<br />

of taken from the Block definition.<br />

> Change the Block coordinates programmatically, for example when generating an<br />

invoice with a variable number of data items.<br />

> Individual spot color names could be supplied in order to match customer requirements<br />

in a print shop application.<br />

Property overrides can be achieved by supplying property names and the corresponding<br />

values in the option list of the fill_*block( ) functions, e.g.<br />

p.fill_textblock(page, "firstname", "Serge", "fontsize=12");<br />

This will override the Block’s internal fontsize property with the supplied value 12. Almost<br />

all property names can be used as options.<br />

Property overrides apply only to the respective function calls; they will not be stored<br />

in the Block definition.<br />

296 Chapter 11: PPS and the <strong>PDFlib</strong> Block Plugin (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!