PR

CakePHP,PHP でPDF出力(実践編)

pc.casey.jp » CakePHPでPDF出力する : https://pc.casey.jp/archives/2011 で準備したので、今回は実践編。早速、単純な帳票を作成したので、よく使うものをまとめておくことにした。

導入部

$fpdf->AddSJISFont();
$fpdf->Open();
$fpdf->AddPage();
$fpdf->SetFont('SJIS', '', 16);

フォントサイズ

SetFontSize(font_size)

$fpdf->SetFontSize(10);

スポンサードリンク

テキスト

Text(y, x, strings)

$fpdf->Text($dy, 10, $data['Customer']['zip']);
$fpdf->Text($dy, 15, $data['Customer']['address']);

セル(表)

Cell(float w, float h, strings, mixed border,  int ln, string align,  int fill,  mixed link  link URL or AddLink() )

$fpdf->Cell($cw_title,  $cl, '品名', 1, 0, 'C', 1); //center + fill
$fpdf->Cell($cw_suuryou, $cl, '数量', 1, 0, 'C', 1); //center + fill
$fpdf->Cell($cw_subtotal, $cl, '小計', 1, 1, 'C', 1); //center + fill + ln
$fpdf->Cell($cw_title,  $cl, $quoteChild['title'], 1, 0, 'L'); //left
$fpdf->Cell($cw_suuryou, $cl, $suuryou,    1, 0, 'R');  // right
$fpdf->Cell($cw_subtotal, $cl, $disp_subtotal,  1, 1, 'R'); // right + ln

セルの色

$fpdf->SetFillColor(204, 204, 204); // #CCCCCC

セル内改行

$fpdf->MultiCell(110, 7, $data['Quote']['conditions'], 1);

位置設定

$fpdf->SetXY($dy, 85);
$fpdf->SetY(85);
$fpdf->SetX(85);

改行

$fpdf->Ln();

処理の終わり

$fpdf->fpdfOutput();

参考文献

コメント