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.

Instead of creating a path object with individual drawing operations you can extract the<br />

clipping path from an imported image:<br />

image = p.load_image("auto", "image.tif", "clippingpathname={path 1}");<br />

/* create a path object from the image’s clipping path */<br />

path = (int) p.info_image(image, "clippingpath", "");<br />

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

throw new Exception("Error: clipping path not found!");<br />

p.draw_path(path, 0, 0, "stroke");<br />

3.2.4 Templates<br />

Templates in PDF. <strong>PDFlib</strong> supports a PDF feature with the technical name Form<br />

XObjects. However, since this term conflicts with interactive forms we refer to this feature<br />

as templates. A <strong>PDFlib</strong> template can be thought of as an off-page buffer into which<br />

text, vector, and image operations are redirected (instead of acting on a regular page).<br />

After the template is finished it can be used much like a raster image, and placed an arbitrary<br />

number of times on arbitrary pages. Like images, templates can be subjected to<br />

geometrical transformations such as scaling or skewing. When a template is used on<br />

multiple pages (or multiply on the same page), the actual PDF operators for constructing<br />

the template are only included once in the PDF file, thereby saving PDF output file<br />

size. Templates suggest themselves for elements which appear repeatedly on several<br />

pages, such as a constant background, a company logo, or graphical elements emitted<br />

by CAD and geographical mapping software. Other typical examples for template usage<br />

include crop and registration marks or custom Asian glyphs.<br />

Using templates with <strong>PDFlib</strong>. Templates can only be defined outside of a page description,<br />

and can be used within a page description. However, templates may also contain<br />

other templates. Obviously, using a template within its own definition is not possible.<br />

Referring to an already defined template on a page is achieved with the fit_image( )<br />

function just like images are placed on the page (see Section 7.3, »Placing Images and<br />

imported PDF Pages«, page 192). The general template idiom in <strong>PDFlib</strong> looks as follows:<br />

/* define the template */<br />

template = p.begin_template_ext(template_width, template_height, "");<br />

...place marks on the template using text, vector, and image functions...<br />

p.end_template_ext(0, 0);<br />

...<br />

p.begin_page(page_width, page_height);<br />

/* use the template */<br />

p.fit_image(template, 0.0, 0.0, "");<br />

...more page marking operations...<br />

p.end_page();<br />

...<br />

p.close_image(template);<br />

All text, graphics, and color functions can be used on a template. However, the following<br />

functions must not be used while constructing a template:<br />

> load_image( ): images must be loaded outside of a template definition, but can be<br />

used within a template.<br />

3.2 Page Descriptions 73

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

Saved successfully!

Ooh no, something went wrong!