2016-08-10 2 views
0

PHP에서 FPDF 라이브러리를 사용하여 PDF를 생성했습니다.PHP의 FPDF 라이브러리에서 서식 지정

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

어떤 변화 :이 같은 출력을 필요

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 파일을 생성 : PDF를 생성 내 다음 코드를 고려하시기 바랍니다 이런 형식의 형식을 만들기 위해 내 코드에서 작성해야합니까?

답변

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