将2 pdf与Zend Framework合并 [英] Merging 2 pdf with Zend Framework

查看:99
本文介绍了将2 pdf与Zend Framework合并的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试合并2个PDF,一个在我的服务器上(不是动态生成),另一个在合并之前生成,并且没有保存在服务器上的任何位置(我只希望我的客户端下载它).所以我只有pdf的内容.两种PDF都具有相同的格式(A4).

I'm trying to merge 2 PDF, one on my server (not dynamically generated) and one generated just before the merge and not saved anywhere on the server (I just want my client to download it). So I only have the pdf's content. Both PDF have the same format (A4).

合并的文件将有2页,也不会保存在服务器上.

The merged file will have 2 pages and won't be saved on server as well.

由于我使用的是Zend Framework,所以我希望使用它的解决方案(无法在线找到...)还有其他建议吗?

Since, I'm using Zend Framework, I would prefer a solution with it (can't find one online...) else any advice ?

(在网上找到了常见的解决方案,但无效)

因为人们不愿意点击.该代码无论如何都在链接中,因为它是错误的并且不起作用.

Edit : because people are lazy to click. The code is in the link anyway since it's wrong and doesn't work.

我尝试下面的脚本,但是我得到了 错误:

I try the script below, but I get the error:

未捕获的异常 带有消息的"Zend_Pdf_Exception" 页面附在一个文档上,但是 在另一个上下文中呈现

Uncaught exception 'Zend_Pdf_Exception' with message 'Page is attached to one documen, but rendered in context of another

推荐答案

好的,在我的问题中有@Gordon评论的指南,我找到了解决方案.

Alright, with the guide from @Gordon 's comment in my question, I got a solution.

  1. 您必须至少具有Zend Framework 1.11(我在1.9中,是第一个错误)(由于对此问题的第三条评论而找到了)
  2. 您必须从要合并的PDF中的clone页,否则,您的应用程序将打印错误(自我解释)(感谢
  1. You must have at least Zend Framework 1.11 (I was in 1.9, first error) (found thanks to the 3rd comment to this question)
  2. You must clone page from the PDF you want to merge, else, your application will print an error (self explanatory one) (found thanks to this slideshare which is very interesting for Zend_Pdf)
  3. The static PDF must be a PDF <= 1.4 (mine was 1.6). Zend_Pdf can't parse PDF which version is > 1.4

我使用了此应用程序来转换我在1.6版中拥有的静态文件到1.4.

I used this application to convert the static files I had in version 1.6 to 1.4.

这是我掌握的工作代码(我知道它没有经过优化,我会在以后做;但是仍然有用)

Here's the rough code I have and work (I know it's not optimised, I'll do it later; but still, it can be useful)

$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());

sendToWebBrowser是将title作为...标题将PDF内容发送到浏览器的功能. $pdf2show->render()将合并的PDF内容生成为字符串.

sendToWebBrowser is a function sending the PDF content to browser with the title as... title. $pdf2show->render() produces the merged PDF content as a string.

这篇关于将2 pdf与Zend Framework合并的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆