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.

7.3 Placing Images and imported PDF Pages<br />

The function fit_image( ) for placing raster images and templates as well as fit_pdi_<br />

page( ) for placing imported PDF pages offer a wealth of options for controlling the<br />

placement on the page. This section demonstrates the most important options by looking<br />

at some common application tasks. A complete list and descriptions of all options<br />

can be found in the <strong>PDFlib</strong> API Reference.<br />

Embedding raster images is easy to accomplish with <strong>PDFlib</strong>. The image file must first<br />

be loaded with load_image( ). This function returns an image handle which can be used<br />

along with positioning and scaling options in fit_image( ).<br />

Embedding imported PDF pages works along the same line. The PDF page must be<br />

opened with open_pdi_page( ) to retrieve a page handle for use in fit_pdi_page( ). The<br />

same positioning and scaling options can be used as for raster images.<br />

All samples in this section work the same for raster images, templates, and imported<br />

PDF pages. Although code samples are only presented for raster images we talk about<br />

placing objects in general. Before calling any of the fit functions a call to load_image( ) or<br />

open_pdi_document( ) and open_pdi_page( ) must be issued. For the sake of simplicity<br />

these calls are not reproduced here.<br />

Cookbook Code samples regarding images and imported PDF pages can be found in the images and pdf_<br />

import categories of the <strong>PDFlib</strong> Cookbook.<br />

7.3.1 Simple Object Placement<br />

Positioning an image at the reference point. By default, an object will be placed in its<br />

original size with the lower left corner at the reference point. In this example we will<br />

place an image with the bottom centered at the reference point. The following code<br />

fragment places the image with the bottom centered at the reference point (0, 0).<br />

p.fit_image(image, 0, 0, "position={center bottom}");<br />

Similarly, you can use the position option with another combination of the keywords<br />

left, right, center, top, and bottom to place the object at the reference point.<br />

Placing an image with scaling.<br />

modifying its size:<br />

The following variation will place the image while<br />

p.fit_image(image, 0, 0, "scale=0.5");<br />

This code fragment places the object with its lower left corner at the point (0, 0) in the<br />

user coordinate system. In addition, the object will be scaled in x and y direction by a<br />

scaling factor of 0.5, which makes it appear at 50 percent of its original size.<br />

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

7.3.2 Placing an Object in a Box<br />

In order to position an object an additional box with specified width and height can be<br />

used. Figure 7.2 shows the output of the examples described below. Note that the gray<br />

box or line is depicted for visualizing the box size only ; it is not part of the actual output.<br />

192 Chapter 7: Importing Images and PDF Pages (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!