カスタム検索
トップページ >Zend Framework >Zend_Pdf >既存ファイルの読込

既存ファイルの読み込み

Zend_Pdfでは、既存ファイルを読み込み、追加でテキストを描画したりすることもできます。

次のファイルを読み込んで、テキストを追記してみます。

hello_world.pdf
Zend_Pdf-ex6.php (既存ファイルに追記)
<?php
/**
 * Zend_Pdf
 * 既存ファイルの読み込み
 */

/** Zend_Pdfのロード */
require_once 'Zend/Pdf.php';


/** 生成 */
// Zend_Pdfのインスタンス生成
$pdf = new Zend_Pdf();

// 既存ファイルの指定
$targetFile '/var/www/html/work/ZendFramework/Zend_Pdf/hello_world.pdf';

// 既存ファイルの読み込み
$pdf Zend_Pdf::load($targetFile);


/** 設定 */
// フォントの指定(標準フォント:Helvetica)
$font Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA);

// フォントを24ptで適用
$pdf->pages[0]->setFont($font24);

// 文字列定義
$text 'Hello PDF!';

// 100pt, 600ptの位置にUTF-8で描画
$pdf->pages[0]->drawText($text100600'UTF-8');


/** 出力 */
// HTTPヘッダ:PDFを出力
header('Content-type: application/pdf');

// HTTPヘッダ:ファイル名をhello_world2.pdfに
header('Content-Disposition: attachment; filename="hello_world2.pdf"');

// ドキュメントを出力
echo $pdf->render();
Zend_Pdf-ex6.phpを実行し、保存後、ビューアーで表示
レンタルサーバーなら使えるねっと
CopyLeft 2010 PEABOX.COM サイト管理者に連絡