>  기사  >  php教程  >  PHP FPDF 클래스 라이브러리 애플리케이션 구현 코드

PHP FPDF 클래스 라이브러리 애플리케이션 구현 코드

黄舟
黄舟원래의
2016-12-14 12:00:471246검색

require('chinese.php');
class PDF 확장 PDF_중국어
{
function Header() //헤더 설정
{
$ this->SetFont('GB','',10);
$this->Write(10,'XX 회사 제품 디렉토리')
$this->Ln(20); /줄 바꿈
}
function Footer() //바닥글 설정
{
$this->SetY(-15)
$this->SetFont('GB' , '',10);
$this->Cell(0,10,'th'.$this->PageNo().'Page');
$conn = mysql_connect("localhost", "root", ""); //데이터베이스에 연결

mysql_select_db("product", $conn) //SQL 실행

$ query_rs_prod = " SELECT * PROM PRODER BY PROD_ID ";

$ RS_PROD = MySQL_QUERY($ Query_RS_PROD, $ Conn) 또는 DIE(mysql_error ())

$ row_rs_prod = _Fetch_assoc($ rs_prod); Totalrows_RS_PROD = MySQL_NUM_ROWS ($rs_prod);

$pdf=new PDF(); //새 FPDF 객체 생성
$pdf->AddGBFont() //중국어 글꼴 설정
$ pdf-> ;Open(); //PDF 만들기 시작

$pdf->AddPage(); //페이지 추가


$pdf->SetFont('GB','', 10); //글꼴 스타일 설정

$header=array('제품 번호', '제품 이름', '제품 유형', '제품 단가') //헤더 설정

$width =array( 20,80,40,20); //각 열의 너비 설정

for($i=0;$i$ pdf->Cell($width[$i],6,$header[$i],1)
$pdf->Ln();

do // 루프 출력 테이블 본문
{
$pdf->Cell($width[0],6,$row_rs_prod['prod_id'],1)

$pdf->Cell($width[ 1],6 ,$row_rs_prod['prod_name'],1);

$pdf->Cell($width[2],6,$row_rs_prod['prod_type'],1)
$pdf ->Cell ($width[3],6,$row_rs_prod['prod_price'],1)
$pdf->Ln()
} while ($row_rs_prod = mysql_fetch_assoc($rs_prod) );

$pdf->Output("product.pdf", true); //PDF 파일 다운로드
?>

코드는 다음과 같습니다.
define('FPDF_FONTPATH','font/'); //글꼴 폴더 경로 정의

require_once('fpdf/fpdf.php') //fpdf 포함 클래스 라이브러리 파일
$pdf= new FPDF('P', 'mm', 'A4') //새 FPDF 객체를 생성하고 용지를 세로로 놓습니다. 단위는 밀리미터이고 용지 크기는 A4입니다.
$pdf->Open(); // PDF 만들기 시작
$pdf->AddPage() //페이지 추가
$pdf->SetFont('Courier','I', 20); //글꼴 스타일 설정
$ pdf->Cell(0,0,'Hello World!') //셀 추가
$pdf->Output(); 브라우저에
?>


코드는 다음과 같습니다.
define('FPDF_FONTPATH','font/') //Define the 글꼴 폴더 경로

require_once('fpdf/fpdf.php'); //fpdf 클래스 라이브러리 파일 포함
$pdf=new FPDF('P', 'mm', 'A4') // 새로운 FPDF 개체를 만들고, 용지를 세로로 놓습니다. 단위는 밀리미터입니다. 용지 크기는 A4
$pdf->Open() //PDF 만들기 시작
$pdf->AddPage() // 페이지 추가
$pdf->SetFont('Courier' ,'I',20) //글꼴 스타일 설정
$pdf->Image('sight.jpg',20,20, 0,0); //sight.jpg
$pdf->Output() //PDF를 브라우저에 출력


코드는 다음과 같습니다.
define( 'FPDF_FONTPATH','font/') //글꼴 폴더 경로 정의

require_once('fpdf/fpdf.php' ); //fpdf 클래스 라이브러리 파일 포함

$pdf=new FPDF('P ', 'mm', 'A4') //새 FPDF 객체를 생성하고 용지를 세로로 놓습니다. 단위는 밀리미터입니다. 용지 크기는 A4
$pdf->Open(); //PDF 만들기 시작
$pdf->AddPage() //페이지 추가
$pdf->SetFont(' Courier','I',20); //글꼴 스타일 설정
$pdf->Cell (60,10,'Hello World!',1) //1에 셀 테두리 추가
$ pdf->Output(); //PDF를 브라우저에 출력
?>


코드는 다음과 같습니다.
define('FPDF_FONTPATH ','font/'); //글꼴 폴더 경로 정의

require_once('fpdf/fpdf.php') //fpdf 클래스 라이브러리 파일 포함

$pdf=new FPDF('P' , 'mm', 'A4'); //새 FPDF 객체를 생성하고 용지를 세로로 놓습니다. 단위는 밀리미터입니다. 용지 크기는 A4
$pdf->Open() //PDF 생성 시작
$pdf->AddPage(); //페이지 추가

$pdf->SetFont( 'Arial','',14) //글꼴 스타일 설정

$header=array('이름','Age','Sex','Salary'); //테이블 헤더 설정
$data=array() //테이블 본문 설정
$data [0] = array('사이먼','24','남성','5,000.00')
$data[1] = array('엘레인','25','여성','6,000.00 ') ;
$data[2] = array('수잔','25','여성','7,000.00')
$data[3] = array('데이비드','26', '남성','8,000.00');

$width=array(40,40,40,40) //각 열의 너비 설정

for($i=0; $i$pdf->Cell($width[$i],6,$header[$i],1)
$ pdf-> ;Ln();

foreach($data as $row) //루프 출력 테이블 본문
{
$pdf->Cell($width[0],6, $row[ 0],1);
$pdf->Cell($width[1],6,$row[1],1)
$pdf->Cell($width[2) ],6 ,$row[2],1);
$pdf->Cell($width[3],6,$row[3],1)
$pdf->Ln( );
}

$pdf->Output(); //PDF를 브라우저에 출력
?>


코드는 다음과 같습니다. 🎜>define('FPDF_FONTPATH','font/'); //글꼴 폴더 경로 정의
require_once('fpdf/fpdf.php') //fpdf 클래스 포함 library file
$pdf= new FPDF('P', 'mm', 'A4'); //새 FPDF 객체를 생성하고 용지를 세로로 배치합니다. 단위는 밀리미터이며 용지 크기는 A4입니다.
$pdf->Open(); // PDF 만들기 시작
$pdf->AddPage() //페이지 추가
$pdf->SetFont('Courier','I',20 ); //글꼴 스타일 설정
$ pdf->Cell(0,0,'Hello, FPDF') //셀 추가 및 중국어 출력
$pdf->Output(); PDF를 브라우저에 출력
? >

코드는 다음과 같습니다.
require('chinese.php')
class PDF 확장 PDF_중국어
{
function Header( ) //헤더 설정
{
$this->SetFont('GB','',10); Write(10,'FPDF 중국어 테스트');
$this->Ln(20)
}

function Footer() //바닥글 설정

{

$this->SetY(-15) ;
$this->SetFont('GB','',10)
$this->Cell(0,10,'페이지 '.$ this->PageNo().' ');
}

$pdf=new PDF(); //PDF 문서 생성
$pdf->AddGBFont() ;

$pdf->

$pdf->AliasNbPages()
$pdf->SetFont('GB' ,'I',20);
$pdf->Cell(0,10,'Hello, FPDF') //한문 조각 출력
$pdf->Output(); >?>


코드는 다음과 같습니다.
$conn = mysql_connect("localhost", "root", ""); 데이터베이스

$colname_rs_article = $_GET['id'] ; //매개변수 ID 가져오기


mysql_select_db("cms", $conn); //SQL 실행
$query_rs_article = sprintf(" SELECT * FROM 기사 WHERE 기사 ID = %s", $colname_rs_article);
$rs_article = mysql_query($query_rs_article, $conn) 또는 die(mysql_error());
$row_rs_article = mysql_fetch_assoc($rs_article);

$totalRows_rs_article = mysql_num_rows($rs_article);


function conv($Text) //반환된 텍스트 처리
{
$Text=htmlspecialchars($Text); //HTML 키 변환 문자
$Text=nl2br($Text); / /줄 바꿈

return $Text;}

?> ;


<글꼴 크기=2> PDF 문서 다운로드 a>






코드는 다음과 같습니다:
require('chinese.php')
class PDF extends PDF_English
{
function Header() / /설정 페이지 눈썹
{
$this->SetFont('GB','',10)
$this->Write(10,'Article System-XX Website'); 🎜>$ this->Ln(20); //줄 바꿈
}
function Footer() //바닥글 설정
{
$this->SetY(-15);
$ this->SetFont('GB','',10)
$this->Cell(0,10,'th'.$this->PageNo().'page' );
}
}
//메인 프로그램 시작
$conn = mysql_connect("localhost", "root", "") //데이터베이스에 연결
$colname_rs_article = $_GET['id' ]; //매개변수 ID 가져오기

mysql_select_db("cms", $conn); //SQL 실행

$query_rs_article = sprintf("SELECT * FROM 기사 WHERE 기사_id = %s", $colname_rs_article) ;
$rs_article = mysql_query($query_rs_article, $conn) 또는 die(mysql_error());
$row_rs_article = mysql_fetch_assoc($rs_article);
$totalRows_rs_article = mysql_num_rows( $rs_article);
//PDF 문서 만들기 시작
$pdf->AddGBFont()
$pdf->Open(); >$pdf->AliasNbPages ();
$pdf->AddPage()
$pdf->SetFont('GB','B',20); ;Cell(0,10, $row_rs_article['title']); //기사 제목 출력
$pdf->Ln() //줄 바꿈
$pdf->SetFont('GB' ,'',10);
$pdf->Cell(0,10,$row_rs_article['author']); //출력 기사 작성자
$pdf->Ln(); $pdf->SetFont(' GB','',12);
$content = $row_rs_article['content']
while($content != "") //기사 작성을 반복합니다. 콘텐츠를 페이지별로 PDF로 가져오기
{
$length = strlen($content); //기사 길이 가져오기
$output = substr($content, 0, 1024) //출력 콘텐츠 가져오기 이 페이지의 1024자마다 1페이지
$pdf->Cell(0,10,$output) //기사 내용 출력
$content = substr($content, 1024, $length) ; //출력되지 않은 나머지 콘텐츠 가져오기
$pdf ->AddPage(); //페이지 변경
}
$pdf->Output($row_rs_article['title'].".pdf" , true); //PDF 파일 출력, 파일명 기사 제목


코드는 다음과 같습니다.
define('FPDF_FONTPATH' ,'font/'); //글꼴 폴더에 대한 경로 정의
require_once('fpdf/fpdf.php') //fpdf 클래스 라이브러리 파일 포함

class PDF는 FPDF를 확장합니다. >{
function Header() //헤더 설정
{
$this->SetFont('Arial','B',15) //헤더 글꼴 설정
$this ->Cell(80); //셀 이동

$ this->Cell(30,10,'Title') //헤더 텍스트 쓰기

$this->Ln(20); //줄바꿈
}

function Footer () //바닥글 설정
{
$this->SetY(-15) //바닥글 위치 설정
$this->SetFont('Arial','I', 8); //바닥글 글꼴 설정
$this->Cell(0,10,'Page - '.$this->PageNo( )); //현재 페이지 번호를 바닥글 내용으로 출력
}

}


$pdf=new PDF('P', 'mm', 'A4') //생성 새 FPDF 개체, 용지를 세로로 배치합니다. 단위는 밀리미터이며 용지 크기는 A4입니다.
$pdf->Open() //PDF 만들기 시작
$pdf->AddPage() / /페이지 추가
$pdf->SetFont('Courier','I ',20) //글꼴 스타일 설정
$pdf->Cell(0,0,'Hello World!') ; //셀 추가
$pdf->Output(); / /브라우저에 PDF 출력

?>


위는 PHP FPDF 클래스 라이브러리 응용 프로그램 구현 코드입니다. 더 많은 관련 내용을 보려면 PHP 중국어 웹사이트(www.php.cn)를 주목하세요!