Php magento FPDF错误:一些数据已经输出,可以';不要发送PDF文件

Php magento FPDF错误:一些数据已经输出,可以';不要发送PDF文件,php,magento,pdf,fpdf,fpdi,Php,Magento,Pdf,Fpdf,Fpdi,我有下一个问题: 我尝试在一个magento phtml中查看pdf这是我的代码: $fileName = Mage::getConfig()->getOptions()->getMediaDir()."/pdf/Gutschein-v2.pdf"; $pdf = new FPDI(); $pdf->addPage(); $pdf->setSourceFile($fileName); $tplIdx = $pdf->importPage(1); // use t

我有下一个问题:

我尝试在一个magento phtml中查看pdf这是我的代码:

$fileName = Mage::getConfig()->getOptions()->getMediaDir()."/pdf/Gutschein-v2.pdf";

$pdf = new FPDI();
$pdf->addPage();
$pdf->setSourceFile($fileName);

$tplIdx = $pdf->importPage(1);
// use the imported page and place it at point 10,10 with a width of 100 mm

$pdf->useTemplate($tplIdx, 10, 10, 100);

// now write some text above the imported page
$pdf->SetFont('Helvetica');
$pdf->SetTextColor(255, 0, 0);
$pdf->SetXY(30, 30);
$pdf->Write(0, 'This is just a simple text');

//ob_start();
$pdf->Output();
//ob_end_flush(); 
当我评论ob_start()时;我在屏幕上看到下一个错误: FPDF错误:某些数据已输出,无法发送PDF文件

当我不评论时,我看到的是正常的pdf格式,而不是带有 在我的pdf中,我尝试使用纯php实现这一点,但一切都很正常示例:

但是对于magento,有些东西不是直觉,也许我不知道如何加载pdf或其他东西。我对magento很陌生

谢谢。

出现错误“某些数据已输出,无法发送PDF文件”,因为Magento已发送标题输出。查看以获取更多信息

因此,FPDF的Output()函数也发送头信息,并将“Content Type”声明为“application/pdf”。这里的主要问题是,不能将PDF文件放在HTML标记之间。PDF是一种自己的格式,需要与HTML不同的植入前机制。与您提供的示例链接一样,PDF文件由带有正确内容类型声明的嵌入标记嵌入:

<embed width="100%" height="100%" name="plugin" src="http://milton.bommelme.com/fpdf/pddf.php" type="application/pdf">
嵌入标记调用getPdf()操作:


答案是,使用是一个选项,但我需要修改PDF,我需要向PDF收费,并使用pdfi我可以修改我的原始PDF:在纯php中可以,但在magento中如何操作,因为它不起作用。
class Foo_Pdf_Controller_SomeController extends Mage_Core_Controller_Front_Action
{

    public function viewAction()
    {
        // View stuff
    }

    public function getPdfAction()
    {
        // create pdf

        $fpdf->output();
    }
}
<embed width="100%" height="100%" name="plugin" src="url_to_getPdf_action" type="application/pdf">