Error in generated pdf file using zend_pdf under Magento

点点圈 提交于 2019-12-25 02:18:12

问题


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

My PDF file is created, but I can't open it with 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. it contains "%PDF-1.4"

How can I add this line programmatically with zend_pdf in my pdf file ?

Thanks for help.


回答1:


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. This answer is technically an RTM statement.



来源:https://stackoverflow.com/questions/8601232/error-in-generated-pdf-file-using-zend-pdf-under-magento

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!