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.

You can not re-use individual elements of imported pages with other <strong>PDFlib</strong> functions.<br />

For example, re-using fonts from imported documents for some other content is<br />

not possible. Instead, all required fonts must be configured in <strong>PDFlib</strong>. If multiple imported<br />

documents contain embedded font data for the same font, PDI will not remove<br />

any duplicate font data. On the other hand, if fonts are missing from some imported<br />

PDF, they will also be missing from the generated PDF output file. As an optimization<br />

you should keep the imported document open as long as possible in order to avoid the<br />

same fonts to be embedded multiple times in the output document.<br />

<strong>PDFlib</strong>+PDI does not change the color of imported PDF documents in any way. For<br />

example, if a PDF contains ICC color profiles these will be retained in the output document.<br />

<strong>PDFlib</strong>+PDI uses the template feature (Form XObjects) for placing imported PDF pages<br />

on the output page. Documents which contain imported pages from other PDF documents<br />

can be processed with <strong>PDFlib</strong>+PDI again.<br />

Code fragments for importing PDF pages. Dealing with pages from existing PDF documents<br />

is possible with a very simple code structure. The following code snippet opens a<br />

page from an existing document, and copies the page contents to a new page in the output<br />

PDF document (which must have been opened before):<br />

int doc, page, pageno = 1;<br />

String filename = "input.pdf";<br />

if (p.begin_document(outfilename, "") == -1) {...}<br />

...<br />

doc = p.open_pdi_document(infilename, "");<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 />

/* dummy page size, will be modified by the adjustpage option */<br />

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

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

p.close_pdi_page(page);<br />

...add more content to the page using <strong>PDFlib</strong> functions...<br />

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

p.close_pdi_document(doc);<br />

The last parameter to fit_pdi_page( ) is an option list which supports a variety of options<br />

for positioning, scaling, and rotating the imported page. Details regarding these options<br />

are discussed in Section 7.3, »Placing Images and imported PDF Pages«, page 192.<br />

Dimensions of imported PDF pages. Imported PDF pages are handled similarly to imported<br />

raster images, and can be placed on the output page using fit_pdi_page( ). By default,<br />

PDI will import the page exactly as it is displayed in Acrobat, in particular:<br />

> cropping will be retained (in technical terms: if a CropBox is present, PDI favors the<br />

CropBox over the MediaBox; see Section 3.2.2, »Page Size«, page 72);<br />

> rotation which has been applied to the page will be retained.<br />

7.2 Importing PDF Pages with PDI 189

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

Saved successfully!

Ooh no, something went wrong!