Last active
July 12, 2018 08:36
-
-
Save rmzaki/7228cb7197bc3b71d24b to your computer and use it in GitHub Desktop.
PDF書き出しサンプル
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once('tcpdf/tcpdf.php'); | |
require_once('fpdi/fpdi.php'); | |
$pdf = new FPDI(); | |
// 余白設定 | |
$pdf->SetMargins(0, 0, 0); | |
// セルパディング設定 | |
$pdf->SetCellPadding(0); | |
// 自動改ページ | |
$pdf->SetAutoPageBreak(false); | |
// ヘッダ、フッダを使用しない | |
$pdf->setPrintHeader(false); | |
$pdf->setPrintFooter(false); | |
// 1ページ目を準備 | |
$pdf->AddPage(); | |
// フォント設定 | |
$font = new TCPDF_FONTS(); | |
$fontX = $font->addTTFfont('tcpdf/fonts/kozgopromedium.php'); | |
$pdf->SetFont($fontX , '', 32,'',true); | |
// PDFファイル読み込み | |
$pdf->setSourceFile('template.pdf'); | |
$page = $pdf->importPage(1); | |
$pdf->useTemplate($page); | |
// Text | |
$pdf->Text(50, 10, 'PDF書き出しテスト'); | |
// 改行 | |
$pdf->Ln(); | |
// セル | |
$pdf->Cell(70, 10, 'セル', 1, 0, 'L'); | |
$pdf->Ln(); | |
// HTML表記 | |
$pdf->writeHTML('<h1>htmlのh1で表記</h1>', true, 0, true, 0); | |
// 画像表示 | |
$pdf->Image('dog.jpg', 10, 100); | |
// PDF出力 | |
$pdf->Output('sample.pdf', 'D'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
【ライブラリ】 | |
[TCPDF] | |
http://www.tcpdf.org/download.php | |
[FPDI] | |
https://www.setasign.com/products/fpdi/downloads/ | |
【フォルダ構成】 | |
pdf.php | |
dog.jpg | |
templete.pdf | |
/tcpdf | |
/config | |
/examples | |
/fonts | |
/include | |
/tools | |
その他php | |
/fpdi | |
/filter | |
その他php | |
【addTTfont()がないと言われた場合】 | |
バージョンアップでメソッドの場所が変わったので2014年12月以前の情報を参考にするとエラーが出る | |
以下、2015年12月時点で実行可能な書き方 | |
$font = new TCPDF_FONTS(); | |
$fontX = $font->addTTFfont('tcpdf/fonts/kozgopromedium.php'); | |
$pdf->SetFont($fontX , '', 32,'',true); | |
【参考URL】 | |
・http://www.tomodigi.com/web/php/php-tcpdf%E3%81%A7%E5%A4%96%E9%83%A8%E3%83%95%E3%82%A9%E3%83%B3%E3%83%88%E3%81%AE%E6%8C%87%E5%AE%9A%EF%BC%88addttffont%E3%81%AE%E4%BF%AE%E6%AD%A3%EF%BC%89/ | |
・http://office-goto.info/php/tcpdf-fpdi-pdf/ (「FPDIはFPDIとFPDI_TPLの2つダウンロードしてください」とあるが、最新バージョンにはあらかじめ入っているので不要) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment