Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/233.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用Magento下的zend_pdf生成pdf文件时出错_Php_Magento_Zend Framework - Fatal编程技术网

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

Php 使用Magento下的zend_pdf生成pdf文件时出错,php,magento,zend-framework,Php,Magento,Zend Framework,我正在尝试创建一个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->setLineC

我正在尝试创建一个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');
我的PDF文件已创建,但无法使用acrobat reader打开它

当我用文本编辑器打开它并与另一个简单的pdf文件进行比较时,我注意到在我生成的pdf文件中缺少了第一行。它包含
“%PDF-1.4”

如何在pdf文件中使用zend_pdf以编程方式添加此行

谢谢您的帮助。

根据第二个save参数仅用于更新已存在的文件。在这种情况下,您正在创建一个新文件,因此不要使用该选项

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


注:这个答案在技术上是一个声明。

重新考虑选择whhtmltopdf选项!如果你使用html作为渲染引擎,然后使用wkhtmltopdf将其弹出到peedo文件中,那么你就不会再为自己的布局感到苦恼了!在这种方法中有一些技巧,如果远程主机等于本地主机,您可以指示Magento呈现不同的模板,从而在peedo-file中获得您想要的html。谢谢,很抱歉我的问题不好:)