您可以使用TCPDF来创建PDF文件。尝试使用以下格式的tcpdf。除此之外,你可以通过tcpdf文档来了解如何使用它。我分享的代码只是如何使用tcpdf创建pdf文件的一个例子。
require_once('tcpdf/tcpdf.php');
error_reporting(0);
// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('your author name');
$pdf->SetTitle('title');
$pdf->SetSubject('subject');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING);
// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
//set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
//set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
//set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
//set some language-dependent strings
$pdf->setLanguageArray($l);
// ---------------------------------------------------------
// set font
$pdf->SetFont('dejavusans', '', 10);
// add a page
$pdf->AddPage();
// writeHTML($html, $ln=true, $fill=false, $reseth=false, $cell=false, $align='')
// writeHTMLCell($w, $h, $x, $y, $html='', $border=0, $ln=0, $fill=0, $reseth=true, $align='', $autopadding=true)
// create some HTML content
$html = $pdf_content;
// output the HTML content
$pdf->writeHTML($html, true, false, true, false, '');
// reset pointer to the last page
$pdf->lastPage();
// ---------------------------------------------------------
//Close and output PDF document
//$pdf->Output('example_006.pdf', 'I');
$pdf_filename = time().".pdf";
$pdf->Output('destination_directory/'.$pdf_filename, 'F');
你可以把你在$pdf_content
变量中获取的数据库信息。希望这对你有所帮助..
这不是你如何创建pdf文件 – 2012-12-06 08:16:46
什么是'$ row [imgdata]'?这不是有效的PHP语法。如果你忘记引号,它将不起作用,因为你没有从表中选择一个名为'imgdata'的列。附:不要使用mysql_XXX函数,使用mysqli或PDO。 – Barmar