我不知道是什麼問題,你的代碼,但在這裏,我使用tcpdf
與創建PDF你的html
。
鋤它會幫助你,
PHP
<?php
include("tcpdf/config/lang/eng.php");
include("tcpdf/tcpdf.php");
error_reporting(E_ALL);
ini_set("display_errors", 1);
// 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('Jaydeep Mor');
$pdf->SetTitle('Example');
$pdf->SetSubject('TCPDF');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
// set default header data
//$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 001', 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 default font subsetting mode
$pdf->setFontSubsetting(true);
// Set font
// dejavusans is a UTF-8 Unicode font, if you only need to
// print standard ASCII chars, you can use core fonts like
// helvetica or times to reduce file size.
$pdf->SetFont('dejavusans', '', 14, '', true);
$pdf->AddPage();
$html_data = '<div style="display:block;position:relative;width:960px;margin:0 auto;">
<div style="text-align: center;">
<h3>INVOICE</h3>
<h1>Test</h1>
<hr />
</div>
<div>
<div style="width:50%;display:inline-block;float:left;">
<span style="float: right;">Date : 02/07/2017</span><br />
<span style="float: right;">Serial Number : 1341951341951499007927</span>
</div>
<div style="clear:both">
</div>
<hr />
<div>
<table style="width:100%">
<thead>
<tr>
<th style="text-align:left">Description</th>
<th style="text-align:right">Amount</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">amt</td>
<td style="text-align:right">199</td>
</tr>
</tbody>
</table>
<hr />
</div>
</div>
</div>';
$html = <<<EOD
$html_data
EOD;
// Print text using writeHTMLCell()
$pdf->writeHTMLCell($w=0, $h=0, $x='', $y='', $html, $border=0, $ln=1, $fill=0, $reseth=true, $align='', $autopadding=true);
// ---------------------------------------------------------
// Close and output PDF document
// This method has several options, check the source code documentation for more information.
$filename = "pdf_exmple.pdf";
// F to save as file
$pdf->Output($filename, 'i');
?>