magento1.7 では、app\code\core\Mage\Wishlist\Helper\Data.php (Data.php) ファイルに次の行を記述します。
public function getpdf()
{
$pdf = new Zend_Pdf();
$font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA);
for($i=0; $i<5; $i++) {
$page = new Zend_Pdf_Page(Zend_Pdf_Page::SIZE_A4);
$page->setFont($font, 24) ->drawText('Hello World page '.$i, 72, 720);
$pdf->pages[] = $page;
}
$pdfString = $pdf->render();
header("Content-Disposition: attachment; filename=myfile.pdf");
header("Content-type: application/x-pdf");
echo $pdfString;
}
この関数を呼び出します
<?php Mage::helper('wishlist')->getpdf();?>
app\design\frontend\base\default\template\wishlist\view.phtml (view.phtml) ファイルの行の直前<div class="my-wishlist">
。ブラウザでmagentoを実行してログインします。次に、[マイ ウィッシュリスト] リンクをクリックすると、ダウンロード フォルダーに myfile.pdf が表示されます。開くとエラーメッセージが表示されます。これらの行を置き換えます
$pdfString = $pdf->render();
header("Content-Disposition: attachment; filename=myfile.pdf");
header("Content-type: application/x-pdf");
echo $pdfString;
と
$pdf->save("mydoc.pdf");
次に、magento1.7 フォルダーにある mydoc.pdf を開きます。エラーなしで開かれ、PDF ドキュメントの各ページに「Hello World」が表示されます。これら 2 つのファイル "myfile.pdf" と "mydoc.pdf" をテキスト エディターで比較すると、"myfile.pdf" に html コンテンツが存在することがわかります。私の問題は、生成された PDF ドキュメントからこれらの html コンテンツを削除する方法が見つからないことです。誰でもこの問題を解決するのを手伝ってくれますか? 上記のコードは、私が行ったことの単なるデモンストレーションであることに注意してください。