3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

PHP: TCPDF と FPDI で PDF を重ね合わせる

Last updated at Posted at 2018-06-19

次のバージョンを使います。

tcpdf 6.3.2
FPDI 2.3.6
ライブラリーはフォルダー直下にあるとします。シンボリックリンクで構いません。

Ubuntu でのインストール

sudo apt install php-tcpdf
$ grep Version tcpdf/tcpdf.php 
// Version     : 6.3.2

FPDI のダウンロード

wget https://www.setasign.com/downloads/2921760/FPDI-2.3.6.tgz

入力は、A4 縦のPDF です。

template.pdf
in01.pdf

pdf_overlap.php
<?php
// ---------------------------------------------------------------------
//	pdf_overlap.php
//
//						Jun/19/2018
//
// ---------------------------------------------------------------------
use setasign\Fpdi\TcpdfFpdi;

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

$pdf = new TcpdfFpdi('L', 'mm', 'A4');

$pdf->setPrintHeader( false );    
$pdf->setPrintFooter( false );

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

$pdf->setSourceFile('in01.pdf');
$pdf->useTemplate($pdf->importPage(1));
$pdf->Output();
// ---------------------------------------------------------------------
?>

実行コマンド

php pdf_overlap.php > out01.pdf
3
3
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
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?