Magento下使用zend_pdf生成的pdf文件出错 [英] Error in generated pdf file using zend_pdf under Magento
问题描述
我正在尝试在Magento phtml文件下创建一个PDF文件,这是我的代码:
I'm trying to create a PDF file, under a Magento phtml file, this is my code :
$pdf = new Zend_Pdf();
$pdf->pages[] = $pdf->newPage(Zend_Pdf_Page::SIZE_A4);
$page=$pdf->pages[0]; // this will get reference to the first page.
$style = new Zend_Pdf_Style();
$style->setLineColor(new Zend_Pdf_Color_Rgb(0,0,0));
$font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_TIMES);
$style->setFont($font,12);
$page->setStyle($style);
$page->drawText('example text here',100,($page->getHeight()-100));
$pdf->render();
$pdf->save('test.pdf','true');
我的PDF文件已创建,但无法使用acrobat Reader打开.
My PDF file is created, but I can't open it with acrobat reader.
当我使用文本编辑器将其打开并与另一个简单的pdf文件进行比较时,我注意到生成的pdf文件中缺少第一行.它包含"%PDF-1.4"
When I open it with a text editor and compare it with another simple pdf files, I noticed that in the first line was missing in my generated pdf file. it contains "%PDF-1.4"
如何在我的pdf文件中使用zend_pdf以编程方式添加此行?
How can I add this line programmatically with zend_pdf in my pdf file ?
感谢您的帮助.
推荐答案
According to the zend manual the second save parameter is only for updating files that already exist. In this case you are creating a new file so don't use that option.
$pdf->save('test.pdf');
PS.从技术上讲,此答案是 RTM 语句.
PS. This answer is technically an RTM statement.
这篇关于Magento下使用zend_pdf生成的pdf文件出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!