简体   繁体   English

使用 Zend_PDF 将 PDF 放入另一个 PDF 文档

[英]Placing a PDF inside another PDF document with Zend_PDF

I have a pdf file of a logo, about 1"x2" in dimension.我有一个徽标的 pdf 文件,尺寸约为 1"x2"。 Can anybody provide the code snippet to import that PDF logo into another PDF file using the Zend_PDF API's?任何人都可以提供代码片段以使用Zend_PDF API 将该 PDF 徽标导入另一个 PDF 文件吗?

Ideally, I'd like to be able to place it like the PNG, TIFF or JPG objects with the Zend_Pdf_Image object.理想情况下,我希望能够像使用 Zend_Pdf_Image 对象放置 PNG、TIFF 或 JPG 对象一样放置它。

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.换句话说,我希望能够将小 1x2" pdf 文档放在 8.5x11" 页面的顶部,而不是使用原始 pdf 作为背景。

Thanks!谢谢!

It looks like as of this date, there's no way to do it using the Zend_PDF API's.看起来截至目前,没有办法使用 Zend_PDF API 来做到这一点。 The Zend_Pdf_Page class has a drawContentStream() which looked promising, but when I checked into it, the method body was empty. Zend_Pdf_Page 类有一个看起来很有希望的 drawContentStream(),但是当我检查它时,方法体是空的。 Maybe a later release of the API will support it.也许以后的 API 版本会支持它。

So, if you want place another PDF inside another dynamically generated PDF document like an image, use FPDI + FPDF/TCPDF .因此,如果您想将另一个 PDF 放入另一个动态生成的 PDF 文档(如图像)中,请使用FPDI + FPDF/TCPD

$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.当然,如果你有一个想要添加水印的 pdf,嗯,这显然是不够的——但在这种情况下,高分辨率 png 可能就足够了。

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).将较小的徽标 pdf 转换为 TIFF/PNG/WhatEver(例如,使用 imagemagick 的convert或 GIMP)。 Then, place this image with the normal Zend API.然后,使用普通 Zend API 放置此图像。

This conversion could also be done on the fly, using the Imagick php class, I would imagine.这种转换也可以使用 Imagick php 类即时完成,我想。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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