2012-03-13 2 views
0

У меня есть пример кода, который создает файл PDF. Моя проблема в том, что мне нужно добавить таблицу в мой PDF-файл. может ли кто-нибудь показать мне, как?Таблица FPDI HTML

вот мой код:

<?php 
require_once('fpdf/fpdf.php'); 
require_once('fpdi/fpdi.php'); 
require_once('html_table2/html_table.php'); 

// initiate FPDI 
$pdf = new FPDI('P','mm','Letter'); 
$htmleditor = new PDF_HTML_Table(); 

// add a page 
$pdf->AddPage(); 
// set the sourcefile 
$pdf->setSourceFile('pdf_docgen_tpl.pdf'); 
// import page 1 
$tplIdx = $pdf->importPage(1); 
// use the imported page and place it at point 10,10 with a width of 100 mm 
$pdf->useTemplate($tplIdx,0,0); 
// now write some text above the imported page 
$pdf->SetFont('Arial','',10); 
$pdf->SetTextColor(255,255,255); 
$pdf->SetXY(175, 26); 
$pdf->Write(0, date("M d,Y"));//date 

$pdf->SetFont('Arial','',20); 
$pdf->SetTextColor(171,199,55); 
$pdf->SetXY(10, 42); 
$pdf->Write(0, "Company Name");//company title 

$pdf->SetFont('Arial','',15); 
$pdf->SetTextColor(255,255,255); 
$pdf->SetXY(10, 50); 
$pdf->Write(0, "NYSE");//nyse 

$compprofile = $htmleditor->ReplaceHTML("<p>Philip Morris International Inc. (PMI), incorporated in 1987, is a holding company. PMI, through its subsidiaries and affiliates and their licensees, is engaged in the manufacture and sale of cigarettes and other tobacco products in markets outside of the United States. As of December 31, 2010, the Company's products were sold in approximately 180 countries. The Company has a range of premium, mid-price and low-price brands. The Company's portfolio comprises both international and local brands. Under the premium-price category, the Company's brands include Marlboro, Merit, Parliament and Virginia Slims. The Company's mid-price brands are L&M and Chesterfield. Its other international brands include Bond Street, Lark, Muratti, Next, Philip Morris and Red & White. PMI also owns a number of local brands, such as Sampoerna A, Dji Sam Soe and Sampoerna Hijau in Indonesia, Fortune, Champion and Hope in the Philippines, Diana in Italy, Optima and Apollo-Soyuz in Russia, Morven Gold in Pakistan,</p>"); 

$pdf->SetFont('Arial','',8); 
$pdf->SetTextColor(0,0,0); 
$pdf->SetXY(10, 71); 
$pdf->MultiCell(98,5,$compprofile);//company profile 
//Line break 
$pdf->Ln(); 
//$pdf->Write(6,  

$image1 = "PM-1331105825.jpg"; 
$pdf->Image($image1, 120, 65, 85); 

$pdf->SetFont('Arial','',10); 
$pdf->SetTextColor(171,199,55); 
$pdf->SetXY(160, 168); 
$pdf->Write(0, "Current Price");//Current Price 

$pdf->SetFont('Arial','',10); 
$pdf->SetTextColor(171,199,55); 
$pdf->SetXY(160, 174); 
$pdf->Write(0, "Volume");//Volime 

$pdf->SetFont('Arial','',10); 
$pdf->SetTextColor(171,199,55); 
$pdf->SetXY(160, 181); 
$pdf->Write(0, "Share Out");//Share Out 

$pdf->SetFont('Arial','',10); 
$pdf->SetTextColor(171,199,55); 
$pdf->SetXY(160, 188); 
$pdf->Write(0, "Market Cap");//Market Cap 

$pdf->SetFont('Arial','',10); 
$pdf->SetTextColor(171,199,55);; 
$pdf->SetXY(160, 201); 
$pdf->Write(0, "Price VS Earning");//Price VS Earning 

$pdf->SetFont('Arial','',10); 
$pdf->SetTextColor(171,199,55); 
$pdf->SetXY(160, 208); 
$pdf->Write(0, "Dividend Yield");//Dividend Yield 

$pdf->SetFont('Arial','',10); 
$pdf->SetTextColor(171,199,55); 
$pdf->SetXY(160, 215); 
$pdf->Write(0, "Earning Per Share");//Earning Per Share 

$pdf->SetFont('Arial','',10); 
$pdf->SetTextColor(171,199,55); 
$pdf->SetXY(160, 222); 
$pdf->Write(0, "Beta");//Beta 

$pdf->SetFont('Arial','',10); 
$pdf->SetTextColor(171,199,55); 
$pdf->SetXY(45, 205); 
$pdf->Write(0, "Sector");//Sector 

$pdf->SetFont('Arial','',10); 
$pdf->SetTextColor(171,199,55); 
$pdf->SetXY(45, 210.5); 
$pdf->Write(0, "Beta");//Beta 

$pdf->SetFont('Arial','',10); 
$pdf->SetTextColor(0,0,0); 
$pdf->SetXY(45, 226); 
$pdf->Write(0, "Beta");//Beta 

$pdf->AddPage(); 
$pdf->setSourceFile('pdf_docgen_tpl.pdf'); 
// import page 1 
$tplIdx = $pdf->importPage(2); 
// use the imported page and place it at point 10,10 with a width of 100 mm 
$pdf->useTemplate($tplIdx,0,0); 

$pdf->SetFont('Arial','',10); 
$pdf->SetTextColor(255,255,255); 
$pdf->SetXY(175, 26); 

$pdf->Write(0, date("M d,Y"));//date 

$pdf->SetFont('Arial','',20); 
$pdf->SetTextColor(171,199,55); 
$pdf->SetXY(10, 42); 
$pdf->Write(0, "Company Name");//company title 

$pdf->SetFont('Arial','',15); 
$pdf->SetTextColor(255,255,255); 
$pdf->SetXY(10, 50); 
$pdf->Write(0, "NYSE");//nyse 

$pdf->SetXY(40, 85); 
$pdf->SetDrawColor(255,255,255); 
$pdf->SetFillColor(255,255,255); 
$pdf->SetLineWidth(0.5); 
$pdf->Cell(135,150,$title,1,1,'C',true); 

$pdf->SetFont('Arial','',12); 
$pdf->SetTextColor(0,0,0); 
$pdf->SetXY(55, 70); 
$pdf->Write(0, "BALANCE SHEET");//Balance SHeet 


//Here is where i need to put the HTML table. Note: the table is saved in the database in HTML code. 

$pdf->Output('newpdf.pdf', 'I'); 
?> 
+0

wkhtmltopdf - ваш друг – Petah

+0

hmmm позвольте мне попробовать XD] \ –

ответ

Смежные вопросы