LoginSignup
2
1

More than 1 year has passed since last update.

PHP: TCPDF でページの下端まで印刷する方法

Last updated at Posted at 2018-04-18

TCPDF を使って1枚のPDF を作成する時、ディフォールトだと下端に描画できません。それを解決する方法です。

pdf->SetAutoPageBreak(false, 0);

ディフォールトだと自動改ページが ON になっています。

次のページを改造して、A4 一杯に書き込んでみます。
PHP: TCPDF だけで日本語を表示

a4_max.php
#! /usr/bin/php
<?php
// ------------------------------------------------------------------
//
//  a4_max.php
//
//                      Jun/11/2021
// ------------------------------------------------------------------

require_once('/usr/share/php/tcpdf/tcpdf.php');

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

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

$pdf->Text(0, 0, "左上");
$pdf->Text(190, 0, "右上");
//
$ymax = 286;
$pdf->Text(0, $ymax, "左下");
$pdf->Text(190, $ymax, "右下");
//

$pdf->Output();

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

実行コマンド

./a4_max.pdf > out01.pdf
2
1
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
2
1