2016-08-10 8 views
0

PHPでFPDFライブラリを使用してPDFを生成しています。 PDFを生成し、私の次のコードを考えてみてください:PHPのFPDFライブラリでの書式設定

Student Details 
Username: abc123 
Name: John 
Parent Details 
Name: Mathew 
Occupation: Businessman 

しかし、私はこのような出力を必要とする:

<?php 
require("fpdf181/fpdf.php"); 
class PDF extends FPDF 
{ 
    //Page header 
    function Header() 
    { 

    } 

    //Page footer 
    function Footer() 
    { 

    } 

} 
$pdf = new PDF('P', 'mm', 'A4'); 
$pdf->AliasNbPages(); 
$pdf->AddPage(); 

$pdf->SetFont('Arial','U',14); 
$pdf->MultiCell(90, 8, "Student Details", 0, 'L'); 

$pdf->SetFont('Arial','B',12); 
$pdf->Cell(32, 8, "Username: "); 
$pdf->SetFont('Arial','',12); 
$pdf->Cell(10, 8, 'abc123', 0, 1); 

$pdf->SetFont('Arial','B',12); 
$pdf->Cell(32, 8, "Name: "); 
$pdf->SetFont('Arial','',12); 
$pdf->Cell(10, 8, 'John', 0, 1); 

$pdf->SetFont('Arial','U',14); 
$pdf->MultiCell(90, 8, "Parent Details", 0, 'L'); 

$pdf->SetFont('Arial','B',12); 
$pdf->Cell(32, 8, "Name: "); 
$pdf->SetFont('Arial','',12); 
$pdf->Cell(10, 8, 'Mathew', 0, 1); 

$pdf->SetFont('Arial','B',12); 
$pdf->Cell(32, 8, "Occupation: "); 
$pdf->SetFont('Arial','',12); 
$pdf->Cell(10, 8, 'Businessman', 0, 1); 

$pdf->Output(); 

?> 

は、今ではこのようになりますPDFを生成

Student Details   Parent Details 
Username: abc123   Name: Mathew 
Name: John     Occupation: Businessman 

どのような変更この種の書式設定を行うために私のコードで行うべきですか?

答えて

1

水平垂直ではないあなたの細胞を置きます。あなたのページが210mm幅であると考えてください。

<?php 
require("fpdf181/fpdf.php"); 
$pdf = new FPDF('P', 'mm', 'A4'); 
$pdf->AliasNbPages(); 
$pdf->AddPage(); 

$pdf->SetFont('Arial','U',14); 
$pdf->Cell(90, 8, "Student Details", 0, 'L'); 
$pdf->Cell(90, 8, "Parent Details", 0, 'L'); 

$pdf->Ln(); 

$pdf->SetFont('Arial','B',12); 
$pdf->Cell(35, 8, "Username: "); 
$pdf->SetFont('Arial','',12); 
$pdf->Cell(55, 8, 'abc123', 0); 

$pdf->SetFont('Arial','B',12); 
$pdf->Cell(35, 8, "Name: "); 
$pdf->SetFont('Arial','',12); 
$pdf->Cell(55, 8, 'Mathew', 0); 

$pdf->Ln(); 

$pdf->Output(); 
+0

これは簡単な方法です。私は、PDFの読み込みを遅らせる複雑なテーブルを作成するのではなく、同じことをやっています。提案していただきありがとうございます。 –

0

テーブルメソッドを使用することができます。ここでの例を働い検索:http://www.fpdf.org/en/tutorial/tuto5.htm

または単にこの試してみてください。(http://www.fpdf.org/en/script/script50.php)を

<?php 
    require('html_table.php'); 

    $pdf=new PDF(); 
    $pdf->AddPage(); 
    $pdf->SetFont('Arial','',12); 

    $html='<table border="0"> 
     <tr> 
      <td width="200" height="30">cell 1</td><td width="200" height="30" bgcolor="#D0D0FF">cell 2</td> 
     </tr> 
     <tr> 
      <td width="200" height="30">cell 3</td><td width="200" height="30">cell 4</td> 
     </tr> 
    </table>'; 

    $pdf->WriteHTML($html); 
    $pdf->Output(); 
?> 
+0

何がhtml_table.phpのパスですか? –

+0

@KPJoy - 拡張のようなfpdfのサポートテーブルを指示するファイルです。ページの一番下からダウンロードすることができます。例:http://www.fpdf.org/en/script/script50.php – Kashyap