Using PHP to generate PDF documents online seems very simple, but in fact it is not that simple, so I decided to write it down to provide you with an idea.
Search "PHP to generate PDF" on the Internet. There are many methods. The following three are the most mentioned online:
■PDFLib: This is a PHP extension library that requires server space to be installed and opened. For the majority of losers who rent space, this method is not feasible.
■TCPDF: TCPDF is a PHP5 function package for quickly generating PDF files. It is expanded and improved based on FPDF. This function package is a bit complicated to use, so I gave up after trying it for hours without success.
■HTML2PDF: The function is very powerful and can directly convert HTML pages into PDF documents. Unfortunately, the environment configuration is complicated and many efforts have failed, so we can only find other ways.
During this period, I also found a paid online PDF conversion platform like pdfcrowd. Obviously, customers would not accept anything that charges a fee. When I almost gave up, I found the native function package FPDF. It is small in size and easy to use. It can produce PDF documents online to meet customer requirements.
The following is a piece of FPDF calling code:
Image('http://www.westationery.com/wp-content/themes/zWenju/images/pdf.jpg',0,0,210);
$this->Ln(15);
}
//Pie de página
function Footer()
{
$this->SetY(-10);
$this->SetFont('Arial','I',8);
$this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
}
}
//Creación del objeto de la clase heredada
$pdf=new PDF();
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->SetFont('Times','',12);
$pdf->Image($imgArray[0],10,25+($i-1)*44,37,37,'',get_permalink($post->ID));
$pdf->SetX(53);
$pdf->Cell(43,7,'Model No.:'.get_post_meta($post->ID, "model_no", true),1,0);
//$this->SetX(110);
$pdf->Cell(105,7,str_replace('″','"',get_the_title()),1,1);
$pdf->SetX(53);
$pdf->Output('we.pdf','I');
?>
Below is a PDF document I produced online using FPDF, with pictures, links, and automatic paging.