LoginSignup
6
5

More than 1 year has passed since last update.

PHP: TCPDF だけで日本語を表示

Last updated at Posted at 2018-04-04

TCPDF だけで、日本語を含む PDF を作成する方法です。

使ったバージョンは、

$ grep Version /usr/share/php/tcpdf/tcpdf.php 
// Version     : 6.3.2

次のフォントが
/usr/share/php/tcpdf/fonts/ に含まれています。

小塚ゴシックPro M (kozgopromedium)
小塚明朝Pro M (kozminproregular)

サンプルのプログラム

japanese01.php
#! /usr/bin/php
<?php
// ------------------------------------------------------------------
require_once('/usr/share/php/tcpdf/tcpdf.php');

$pdf = new TCPDF("L", "mm", "A4", true, "UTF-8" );
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);
$pdf->AddPage();

$pdf->SetFont('kozminproregular', '', 24);

$pdf->Text(0, 0, "alphabetica ABCDEFG" );
//
$pdf->Text(0, 15, "日本語を表示" );


$pdf->SetFont('kozgopromedium', '', 24);
$pdf->Text(0, 50, "日本語を表示" );

$pdf->Output();

// ------------------------------------------------------------------
?>

実行コマンド

./japanese01.php > out01.pdf

次の PDF ファイルが作成されます。
tcpdf_jun1101.png

6
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
5