PDFlib 8 Windows COM/.NET Tutorial
PDFlib 8 Windows COM/.NET Tutorial
PDFlib 8 Windows COM/.NET Tutorial
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Fig. 7.8<br />
Adjusting the page<br />
size. Left to right:<br />
exact, enlarge,<br />
shrink<br />
7.3.5 Adjusting the Page Size<br />
Adjusting the page size to an image. In the next example we will automatically adjust<br />
the page size to the object’s size. This can be useful, for example, for archiving images in<br />
the PDF format. The reference point (x, y) can be used to specify whether the page will<br />
have exactly the object’s size, or somewhat larger or smaller. When enlarging the page<br />
size (see Figure 7.8) some border will be kept around the image. If the page size is smaller<br />
than the image some parts of the image will be clipped. Let’s start with exactly matching<br />
the page size to the object’s size:<br />
p.fit_image(image, 0, 0, "adjustpage");<br />
The next code fragment increases the page size by 40 units in x and y direction, creating<br />
a white border around the object:<br />
p.fit_image(image, 40, 40, "adjustpage");<br />
The next code fragment decreases the page size by 40 units in x and y direction. The object<br />
will be clipped at the page borders, and some area within the object (with a width of<br />
40 units) will be invisible:<br />
p.fit_image(image, -40, -40, "adjustpage");<br />
In addition to placing by means of x and y coordinates (which specify the object’s distance<br />
from the page edges, or the coordinate axes in the general case) you can also specify<br />
a target box. This is a rectangular area in which the object will be placed subject to<br />
various formatting rules. These can be controlled with the boxsize, fitmethod and<br />
position options.<br />
Cloning the page boxes of an imported PDF page. You can copy all relevant page boxes<br />
(MediaBox, CropBox) etc. of an imported PDF page to the current output page. The<br />
cloneboxes option must be supplied to open_pdi_page( ) to read all relevant box values,<br />
and again in fit_pdi_page( ) to apply the box values to the current page:<br />
/* Open the page and clone the page box entries */<br />
inpage = p.open_pdi_page(indoc, 1, "cloneboxes");<br />
...<br />
/* Start the output page with a dummy page size */<br />
p.begin_page_ext(10, 10, "");<br />
...<br />
/*<br />
* Place the imported page on the output page, and clone all<br />
* page boxes which are present in the input page; this will<br />
* override the dummy size used in begin_page_ext().<br />
*/<br />
p.fit_pdi_page(inpage, 0, 0, "cloneboxes");<br />
7.3 Placing Images and imported PDF Pages 197