Help us understand the problem. What is going on with this article?

PHPでTCPDFを使ってHTMLをPDF化する

More than 3 years have passed since last update.

この記事の続きです。

環境

Mac OS X El Capitan 10.11.4
PHP 5.6.24
CodeIgniter 2.2.0(古い。が、他のFWでも参考になるかと思います)

ライブラリのインストール

composer require tecnickcom/tcpdf
requireを付けてcomposer.jsonにも追加。

実装

// composerでインストールしたライブラリを参照する
require_once('./vendor/tecnickcom/tcpdf/tcpdf.php');

// 用紙の方向、用紙サイズを指定する
$tcpdf = new TCPDF('L', "mm",'A4');
$tcpdf->setPrintHeader(false);
$tcpdf->setPrintFooter(false);
$tcpdf->AddPage();

// CodeIgniterのviewの第三引数をtrueにしてhtml文字列として扱う
$html = $this->load->view('open_position', $this->data, true);

$tcpdf->WriteHTML($html, true, 0, false, true, 'L');
// 出力用バッファの内容を消去
ob_end_clean();
$tcpdf->Output($file_name, "D");

CodeIgniterらしくapplication/librariesにクラス化しておくと良い感じ。

noratmt
noranekoworks
業務システム、Webサービス、モバイルアプリを中心に開発するエンジニア集団です。
http://www.noraneko.works/
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした