简体   繁体   中英

Placing a PDF inside another PDF document with Zend_PDF

I have a pdf file of a logo, about 1"x2" in dimension. Can anybody provide the code snippet to import that PDF logo into another PDF file using the Zend_PDF API's?

Ideally, I'd like to be able to place it like the PNG, TIFF or JPG objects with the Zend_Pdf_Image object.

In other words, I want to be able to place the little 1x2" pdf document on top of a 8.5x11" page, not use the original pdf as a background.

Thanks!

It looks like as of this date, there's no way to do it using the Zend_PDF API's. The Zend_Pdf_Page class has a drawContentStream() which looked promising, but when I checked into it, the method body was empty. Maybe a later release of the API will support it.

So, if you want place another PDF inside another dynamically generated PDF document like an image, use FPDI + FPDF/TCPDF .

$pdf = & new FPDI ('P', 'in', 'Letter' );
$pagecount = $pdf->setSourceFile ( APP . 'logo.pdf' );
$tplidx = $pdf->importPage ( 1, '/MediaBox' );

$pdf->addPage ();
$pdf->useTemplate ( $tplidx, 1, 1 );
$pdf->Output ( 'output.pdf', 'F' );

I believe you can clone a page --like a template. Not sure if this is enough for you, it does look like the preferred way to do things. Of course, if you have a pdf that you want to add a, say, watermark, to, uhh, this is clearly insufficient --but in this case a hi-res png would probably suffice.

Not what you asked for, but probably what you need (:

Convert the smaller logo pdf to a TIFF/PNG/WhatEver (using, for example, imagemagick's convert , or the GIMP). Then, place this image with the normal Zend API.

This conversion could also be done on the fly, using the Imagick php class, I would imagine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM