【发布时间】:2015-09-28 09:14:14
【问题描述】:
我正在使用 Laravel 4.2
对 ajax 很陌生,我不知道在 .done 中放置什么来显示 PDF。
我在方法中写的(缺少html变量...它很大):
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->SetCreator("Office");
$pdf->SetAuthor('Office');
$pdf->SetTitle('TCPDF Example 061');
$pdf->SetSubject('TCPDF Tutorial');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 061', PDF_HEADER_STRING);
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
$pdf->SetMargins(10, 5, 10);
$pdf->SetHeaderMargin(5);
$pdf->SetFooterMargin(0);
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
require_once(dirname(__FILE__).'/lang/eng.php');
$pdf->setLanguageArray($l);
}
$pdf->SetPrintHeader(false);
$pdf->SetPrintFooter(false);
$pdf->SetFont('helvetica', '', 10);
$pdf->AddPage();
$pdf->writeHTML($html, true, 0, true, 0);
$pdf->lastPage();
$pdf->Output('test.pdf', 'I');
我在视图中写的:
$('#btnPrint').click(function() {
$.ajax({
url: '{{ route('getPDF') }}',
type: 'POST',
cache: false,
data: {data: html},
})
.done(function(data) {
// what should be placed here
})
.fail(function() {
console.log("error");
});
});
【问题讨论】:
标签: javascript php jquery ajax tcpdf