好的,在@Gordon對我的問題的評論中,我得到了一個解決方案。
- 您必須至少Zend Framework的1.11(我是在1.9,第一個錯誤)(發現由於對這個問題的第三個評論)
- 您必須要合併的PDF
clone
頁面,否則,您的應用程序將打印一個錯誤(自我解釋的錯誤)(發現感謝this slideshare這對Zend_Pdf非常有趣)
- 靜態PDF必須是PDF < = 1.4(我的是1.6)。 Zend_Pdf無法解析PDF版本大於1.4
我用this application將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());
sendToWebBrowser
是發送PDF內容的功能瀏覽器的標題爲title
。 $pdf2show->render()
以字符串形式生成合並的PDF內容。
澄清「不工作」 – Gordon 2010-11-23 08:57:31
@Gordon:好,請閱讀鏈接的頁面> _> _I嘗試下面的腳本,但我得到的錯誤:未捕獲的異常「Zend_Pdf_Exception」有消息「頁面連接到一個文件,但在另一個環境中渲染_我知道我討厭_doesn't工作問題,但嚴重的是,在這裏,你只需要閱讀... – Shikiryu 2010-11-23 08:59:15
謝謝澄清。只要儘量在你的問題中儘可能完整,而不是指責你要求懶惰的人。不把所有的信息放在首位都是懶惰的。另外,儘管用戶有錯誤,您是否嘗試過給出的代碼?我GOOGLE了錯誤信息和[這個特殊的錯誤似乎是固定在1.11](http://framework.zend.com/issues/browse/ZF-449) – Gordon 2010-11-23 09:12:55