カスタム検索

ページサイズ

ページの作成には、newPage()メソッドを使用するか、Zend_Pdf_Pageインスタンスを生成しますが、引数にはページサイズを指定します。定義済みの定数を指定するか、任意のサイズを指定します。

定義済み定数の指定

ページサイズの定義済み定数は以下のとおりです。

定数名 サイズ
Zend_Pdf_Page::SIZE_A4 A4縦(595pt×842pt)
Zend_Pdf_Page::SIZE_A4_LANDSCAPE A4横(842pt×595pt)
Zend_Pdf_Page::SIZE_LETTER USレター縦(612pt×792pt)
Zend_Pdf_Page::SIZE_LETTER_LANDSCAPE USレター横(792×612pt)
Zend_Pdf-ex3.php (ページサイズを定数で指定)
<?php
/**
 * Zend_Pdf
 * ページサイズを定義済み定数で指定
 */

/** Zend_Pdfの読み込み */
require_once 'Zend/Pdf.php';


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

// ページを作成
// A4縦
//$pdf->pages[] = $pdf->newPage(Zend_Pdf_Page::SIZE_A4);
// A4横
//$pdf->pages[] = $pdf->newPage(Zend_Pdf_Page::SIZE_A4_LANDSCAPE);
// USレター縦
//$pdf->pages[] = $pdf->newPage(Zend_Pdf_Page::SIZE_LETTER);
// USレター横
$pdf->pages[] = $pdf->newPage(Zend_Pdf_Page::SIZE_LETTER_LANDSCAPE);


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

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

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

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


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

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

// ドキュメントを出力
echo $pdf->render();

任意のサイズを指定

任意のサイズを指定するには、横と縦の2つの値を引数に指定します。

Zend_Pdf-ex4.php (ページサイズを任意値で指定)
<?php
/**
 * Zend_Pdf
 * ページサイズを任意値で指定
 */

/** Zend_Pdfの読み込み */
require_once 'Zend/Pdf.php';


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

// 300*500のページを作成
$pdf->pages[] = $pdf->newPage(300500);


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

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

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

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


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

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

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