Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
4
Help us understand the problem. What is going on with this article?
@ekzemplaro

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

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

4
Help us understand the problem. What is going on with this article?
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
4
Help us understand the problem. What is going on with this article?