Shi*_*ryu 5 php pdf merge zend-framework
我正在尝试合并2个PDF,一个在我的服务器上(非动态生成),一个在合并之前生成,而不是保存在服务器上的任何地方(我只是希望我的客户端下载它).所以我只有pdf的内容.两种PDF都具有相同的格式(A4).
合并的文件将有2页,也不会保存在服务器上.
既然,我正在使用Zend Framework,我更喜欢使用它的解决方案(在网上找不到一个......)或者其他建议吗?
编辑:因为人们懒得点击.无论如何代码都在链接中,因为它是错误的并且不起作用.
我尝试下面的脚本,但我收到错误:
未捕获的异常'Zend_Pdf_Exception',消息'Page附加到一个文档,但在另一个文档的上下文中呈现
好的,根据@Gordon在我的问题中的评论指南,我得到了一个解决方案.
clone从要合并的PDF页面进行分页,否则,您的应用程序将打印错误(自解释的)(感谢此幻灯片共享对Zend_Pdf非常有趣)我使用此应用程序将我在1.6版本中的静态文件转换为1.4.
这是我的粗略代码和工作(我知道它没有优化,我会稍后再做;但是,它仍然有用)
$pdf2show = new Zend_Pdf(); // Initializing the merged PDF
$pdf1 = Zend_Pdf::parse($pdfContent, 1); // $pdfContent is the generated one, got the content...
$template = clone $pdf1->pages[0]; // cloning the page (a must do)
$page1 = new Zend_Pdf_Page($template); // Creating the first page of the merged PDF with the previous content
$pdf2show->pages[] = $page1; // Adding this page to the final PDF
$pdf2 = Zend_Pdf::load('urlToYourPDF.pdf'); // Loading the statif PDF
$template2 = clone $pdf2->pages[0]; // cloning the page (a must do)
$page2 = new Zend_Pdf_Page($template2); // Creating the second page of the merged PDF with the previous content
$pdf2show->pages[] = $page2; // Adding this page to the final PDF
sendToWebBrowser('title', $pdf2show->render());
Run Code Online (Sandbox Code Playgroud)
sendToWebBrowser是一个函数将PDF内容发送到具有titleas ...标题的浏览器.
$pdf2show->render()将合并的PDF内容生成为字符串.