LoginSignup
3
4

More than 1 year has passed since last update.

PHP: TCPDF と FPDI で PDF に加筆

Last updated at Posted at 2018-06-19

次のプログラムを改造して、テンプレートの PDF に加筆をしてみました。
TCPDF と FPDI で PDF を重ね合わせる

pdf_template.php
<?php
// --------------------------------------------------------------------
/*

    pdf_template.php

                    Jun/09/2021


*/
// --------------------------------------------------------------------
use setasign\Fpdi\TcpdfFpdi;

require_once '/usr/share/php/tcpdf/tcpdf.php';
require_once 'FPDI-2.3.6/src/autoload.php';

$pdf_in_a = $argv[1];

fputs (STDERR,"*** 開始 ***\n");

$pdf = new TcpdfFpdi('P', 'mm', 'A4', true, "UTF-8" );

if ($pdf instanceof \TCPDF) {
    $pdf->setPrintHeader(false);
    $pdf->setPrintFooter(false);
}

$pdf->setSourceFile($pdf_in_a);

$pdf->AddPage('P', 'A4');
$pdf->useTemplate($pdf->importPage(1));

$font_path = '/usr/share/fonts/opentype/ipafont-mincho/ipamp.ttf';

if (file_exists($font_path))
    {
    $font = new TCPDF_FONTS();

    $fontX = $font->addTTFfont($font_path);
    $pdf->SetFont($fontX , '', 16,'',true);
    }

$pdf->Text(50, 60, "alphabetica ABCDEFG", 0.1 );

$pdf->Text(100, 80, "日本語を表示します。",0.1 );
$pdf->Text(100, 120, "テストです。",0.1 );

$pdf->Output();

fputs (STDERR,"*** 終了 ***\n");
// --------------------------------------------------------------------
?>

実行コマンド

php pdf_template.php template.pdf > out01.pdf
3
4
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
3
4