简体   繁体   English

在Magento下使用zend_pdf生成的pdf文件出错

[英]Error in generated pdf file using zend_pdf under Magento

I'm trying to create a PDF file, under a Magento phtml file, this is my code : 我正在尝试创建一个PDF文件,在Magento phtml文件下,这是我的代码:

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

My PDF file is created, but I can't open it with acrobat reader. 我的PDF文件已创建,但我无法使用acrobat reader打开它。

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. 当我用文本编辑器打开它并将其与另一个简单的pdf文件进行比较时,我注意到在生成的pdf文件中缺少第一行。 it contains "%PDF-1.4" 它包含"%PDF-1.4"

How can I add this line programmatically with zend_pdf in my pdf file ? 如何在我的pdf文件中以编程方式使用zend_pdf添加此行?

Thanks for help. 感谢帮助。

According to the zend manual the second save parameter is only for updating files that already exist. 根据zend手册 ,第二个保存参数仅用于更新已存在的文件。 In this case you are creating a new file so don't use that option. 在这种情况下,您正在创建一个新文件,因此请勿使用该选项。

$pdf->save('test.pdf');

PS. PS。 This answer is technically an RTM statement. 这个答案在技术上是一个RTM声明。

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

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