10.07.2015 Views

Download - Multivac!

Download - Multivac!

Download - Multivac!

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

6 Importing Images and PDF PagesPDFlib offers a variety of features for importing raster images and pages from existingPDF documents, and placing them on the page. This chapter covers the details of dealingwith raster images and importing pages from existing PDF documents. Placing imagesand PDF pages on an output page is discussed in Section 7.3, »Placing Images andImported PDF Pages«, page 158.Cookbook Code samples regarding image issues can be found in the images category of the PDFlib Cookbook.6.1 Importing Raster Images6.1.1 Basic Image HandlingEmbedding raster images with PDFlib is easy to accomplish. First, the image file has tobe opened with a PDFlib function which does a brief analysis of the image parameters.The PDF_load_image( ) function returns a handle which serves as an image descriptor.This handle can be used in a call to PDF_fit_image( ), along with positioning and scalingparameters:image = p.load_image("auto", "image.jpg", "");if (image == -1)throw new Exception("Error: " + p.get_errmsg());p.fit_image(image, 0.0, 0.0, "");p.close_image(image);The last argument to the PDF_fit_image( ) function is an option list which supports a varietyof options for positioning, scaling, and rotating the image. Details regarding theseoptions are discussed in Section 7.3, »Placing Images and Imported PDF Pages«, page 158.Cookbook A full code sample can be found in the Cookbook topic images/starter_image.Re-using image data. PDFlib supports an important PDF optimization technique forusing repeated raster images. Consider a layout with a constant logo or background onmultiple pages. In this situation it is possible to include the actual image data only oncein the PDF, and generate only a reference on each of the pages where the image is used.Simply load the image file once, and call PDF_fit_image( ) every time you want to placethe logo or background on a particular page. You can place the image on multiple pages,or use different scaling factors for different occurrences of the same image (as long asthe image hasn’t been closed). Depending on the image’s size and the number of occurrences,this technique can result in enormous space savings.Scaling and dpi calculations. PDFlib never changes the number of pixels in an importedimage. Scaling either blows up or shrinks image pixels, but doesn’t do any downsampling(the number of pixels in an image will always remain the same). A scaling factor of1 results in a pixel size of 1 unit in user coordinates. In other words, the image will be importedwith its native resolution (or 72 dpi if it doesn’t contain any resolution informa-6.1 Importing Raster Images 121

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

Saved successfully!

Ooh no, something went wrong!