yusuke1209kitamura
@yusuke1209kitamura (murakita)

Are you sure you want to delete the question?

If your question is resolved, you may close it.

Leaving a resolved question undeleted may help others!

We hope you find it useful!

TCPDFを使ってPDFファイルを出力したい

やりたいこと

TCPDFで文中にデータベースから取得した値をwhile文で回して、PDFファイルを作成したいです。
また、下記のコードにできるだけ変更を加えずにPDF化したいと考えております。

エラー内容

PDFを表示させようとすると、「このページは動作していません」と表示されます。
そのためデバックなどができずに困っております。

記述したコード

前のページでクリックボタンを押すと、PDFページが表示されるという流れです。
PDFの出力内容にPHPを使わずHTMLだけで実行すると、PDFが表示されるので、前のページのリンクやTCPDFライブラリの読み込みなどの問題なさそうです。

<?php
include( 'set.inc' );
//PDFライブラリの読み込み
require_once('tcpdf/tcpdf.php');
session_cache_limiter('none');

$sql = "SET NAMES utf8";
mysql_query($sql);

//TCPDFインスタンスを作成
$tcpdf = new TCPDF();

//フォント指定
$tcpdf->SetFont("kozgopromedium", "", 10);

// 印刷ヘッダー非表示
$tcpdf->setPrintHeader(true);

// 印刷フッター非表示
// $tcpdf->setPrintFooter(false);
$tcpdf->AddPage();

$user_id = $_GET['user_id'];
$to_user_id = $_GET['to_user_id'];
$page = $_GET['page'];
$sql = $_GET['sql'];


//echo $sql;

    $result = mysql_query($sql);

?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title> </title>


</head>
<body style="margin:0; padding:0;">
<div style="width:900px; padding-top:10px;">



<?
if($page == 2){
    echo "
<div style='float:left; width:750px; height:190px; padding:30px 20px 30px 40px; font-size:18px; font-weight:bold; line-height:150%;'>
        
</div>";
}
if($page == 3){
    echo "<div style='float:left; width:750px; height:190px; padding:30px 20px 30px 40px; font-size:18px; font-weight:bold; line-height:150%;'>
        
</div>
<div style='float:left; width:750px; height:150px; padding:30px 20px 30px 40px; font-size:18px; font-weight:bold; line-height:150%;'>
        
</div>";
}
if($page == 4){
    echo "<div style='float:left; width:750px; height:190px; padding:30px 20px 30px 40px; font-size:18px; font-weight:bold; line-height:150%;'>
        
</div><div style='float:left; width:750px; height:150px; padding:30px 20px 30px 40px; font-size:18px; font-weight:bold; line-height:150%;'>
        
</div><div style='float:left; width:750px; height:190px; padding:30px 20px 30px 40px; font-size:18px; font-weight:bold; line-height:150%;'>
        
</div>";
}
if($page == 5){
    echo "<div style='float:left; width:750px; height:190px; padding:30px 20px 30px 40px; font-size:18px; font-weight:bold; line-height:150%;'>
        
</div><div style='float:left; width:750px; height:150px; padding:30px 20px 30px 40px; font-size:18px; font-weight:bold; line-height:150%;'>
        
</div><div style='float:left; width:750px; height:150px; padding:30px 20px 30px 40px; font-size:18px; font-weight:bold; line-height:150%;'>
        
</div><div style='float:left; width:750px; height:190px; padding:30px 20px 30px 40px; font-size:18px; font-weight:bold; line-height:150%;'>
        
</div>";
}
?>



<?

// $tcpdf->Text($user_id);
while( $row = mysql_fetch_array($result) ) {
        $user_id = $row['user_id'];
        $name = $row['name'];
        $zip = $row['zip'];
        $addr = $row['addr'];
        $banchi = $row['banchi'];
        $room = $row['room'];
        $tel = $row['tel'];

        $zip1 = substr($zip, 0, 3);
        $zip2 = substr($zip, -4);
        $zip = $zip1."-".$zip2;


        $addr_num = strlen($addr);
        $banchi_num = strlen($banchi);

        switch ($addr_num) {
    case 14:
        $font_size = "26";
        break;
    case 15:
        $font_size = "26";
        break;
    case 16:
        $font_size = "26";
        break;
    case 17:
        $font_size = "26";
        break;
    case 18:
        $font_size = "26";
        break;
    case 19:
        $font_size = "26";
        break;
    case 20:
        $font_size = "26";
        break;
    case 21:
        $font_size = "26";
        break;
    case 22:
        $font_size = "26";
        break;
    case 23:
        $font_size = "26";
        break;
    case 24:
        $font_size = "26";
        break;
    case 25:
        $font_size = "26";
        break;
    case 26:
        $font_size = "24";
        break;
    case 27:
        $font_size = "24";
        break;
    case 28:
        $font_size = "24";
        break;
    case 29:
        $font_size = "24";
        break;
    case 30:
        $font_size = "24";
        break;
    case 31:
        $font_size = "24";
        break;
    case 32:
        $font_size = "24";
        break;
    case 33:
        $font_size = "24";
        break;
    case 34:
        $font_size = "24";
        break;
    case 35:
        $font_size = "24";
        break;
    case 36:
        $font_size = "24";
        break;
    case 37:
        $font_size = "24";
        break;
    case 38:
        $font_size = "24";
        break;
    case 39:
        $font_size = "23";
        break;
    case 40:
        $font_size = "23";
        break;
    case 41:
        $font_size = "22";
        break;
    case 42:
        $font_size = "22";
        break;
    case 43:
        $font_size = "21";
        break;
    case 44:
        $font_size = "21";
        break;
    case 45:
        $font_size = "21";
        break;
    case 46:
        $font_size = "21";
        break;
    case 47:
        $font_size = "21";
        break;
    case 48:
        $font_size = "21";
        break;
    case 49:
        $font_size = "20";
        break;
    case 50:
        $font_size = "20";
        break;
    case 51:
        $font_size = "18";
        break;
    case 52:
        $font_size = "18";
        break;
        }


        switch ($banchi_num) {
    case 14:
        $font_size_ban = "26";
        break;
    case 15:
        $font_size_ban = "26";
        break;
    case 16:
        $font_size_ban = "26";
        break;
    case 17:
        $font_size_ban = "26";
        break;
    case 18:
        $font_size_ban = "26";
        break;
    case 19:
        $font_size_ban = "26";
        break;
    case 20:
        $font_size_ban = "26";
        break;
    case 21:
        $font_size_ban = "26";
        break;
    case 22:
        $font_size_ban = "26";
        break;
    case 23:
        $font_size_ban = "26";
        break;
    case 24:
        $font_size_ban = "26";
        break;
    case 25:
        $font_size_ban = "26";
        break;
    case 26:
        $font_size_ban = "24";
        break;
    case 27:
        $font_size_ban = "24";
        break;
    case 28:
        $font_size_ban = "24";
        break;
    case 29:
        $font_size_ban = "24";
        break;
    case 30:
        $font_size_ban = "24";
        break;
    case 31:
        $font_size_ban = "24";
        break;
    case 32:
        $font_size_ban = "24";
        break;
    case 33:
        $font_size_ban = "24";
        break;
    case 34:
        $font_size_ban = "24";
        break;
    case 35:
        $font_size_ban = "24";
        break;
    case 36:
        $font_size_ban = "24";
        break;
    case 37:
        $font_size_ban = "24";
        break;
    case 38:
        $font_size_ban = "24";
        break;
    case 39:
        $font_size_ban = "23";
        break;
    case 40:
        $font_size_ban = "23";
        break;
    case 41:
        $font_size_ban = "22";
        break;
    case 42:
        $font_size_ban = "22";
        break;
    case 43:
        $font_size_ban = "21";
        break;
    case 44:
        $font_size_ban = "21";
        break;
    case 45:
        $font_size_ban = "21";
        break;
    case 46:
        $font_size_ban = "21";
        break;
    case 47:
        $font_size_ban = "21";
        break;
    case 48:
        $font_size_ban = "21";
        break;
    case 49:
        $font_size_ban = "20";
        break;
    case 50:
        $font_size_ban = "20";
        break;
    case 51:
        $font_size_ban = "18";
        break;
    case 52:
        $font_size_ban = "18";
        break;


}

?>


<div style="float:left; width:380px; height:190px; padding:30px 20px 30px 40px; font-size:18px; font-weight:bold; font-family:'ヒラギノ明朝 Pro W3', 'Hiragino Mincho Pro', serif; line-height:150%;">
<table width="370" border="0">
  <tr>
    <td><span style="font-size:12px; float:right; border:1px solid #000; padding:0px 3px;">サンプル在中</span>〒<span style="font-size:18px;"><?= $zip?></span></td>
    </tr>
  <tr>
    <td><span style="font-size:<?=$font_size?>px;"><?= $addr?></span></td>
    </tr>
  <tr>
    <td style="text-align:left;"><span style="font-size:<?=$font_size_ban?>px;"><?=$banchi." ".$room?></span></td>
    </tr>
  <tr>
    <td style="text-align:left;"><br />
<span style="font-size:18px;">
      <?=$user_id?>
</span></td>
  </tr>
  <tr>
    <td style="text-align:center;"><span style="font-size:32px;"><span style="font-size:18px;"> 
    </span>
      <?=$name?> 様</span></td>
    </tr>
</table>

</div>
<?
}
?>
</div>
</body>
</html>


<?php
ob_end_clean();
$tcpdf->Output("print_saple_old.pdf", "I"); // pdf表示設定
?>

0

No Answers yet.

Your answer might help someone💌