你不能这样做在Javascript 为PDF格式,你可以使用http://www.fpdf.org/
它非常容易使用,下面是创建具有条形码的门票事件的样本:
$pdf = new FPDF();
$pdf->AddPage("H",array(100,160));
$pdf->AddFont('code128',"", 'code128.php');
$pdf->AddFont('3of9',"", '3of9.php');
$pdf->Image('img/'.$alias.'/ticket.gif', -20, 0, 180, 100);
//blank
$pdf->SetFont('arial','',6);
$pdf->Cell(145,10,'', 0,1,'R');
// EVENT DATE
$pdf->SetFont('arial','',6);
$pdf->Cell(145,3,'Event Date:', 0,1,'R');
$pdf->SetFont('arial','B',8);
$pdf->Cell(145,5,$event_date, 0,1,'R');
// EVENT TIME
$pdf->SetFont('arial','',6);
$pdf->Cell(145,3,'Event Time:', 0,1,'R');
$pdf->SetFont('arial','B',8);
$pdf->Cell(145,5,$event_time, 0,1,'R');
// TICKET SERIAL
$pdf->SetFont('arial','',6);
$pdf->Cell(145,5, "Class: $class_code | Serial Number: $serial_number", 0,1,'R');
$pdf->SetFont('3of9','',10);
$pdf->Cell(145,5, "*$serial_number*", 0,1,'R');
// TICKET PASS
$pdf->SetFont('arial','',6);
$pdf->Cell(145,5, "Passcode: $passcode", 0,1,'R');
$pdf->SetFont('3of9','',10);
$pdf->Cell(145,5, "*$passcode*", 0,1,'R');
// PURCHASE BY
$pdf->SetFont('arial','',6);
$pdf->Cell(145,3, "Purchased by : $purchased_by", 0,1,'R');
// Payment Method
$pdf->SetFont('arial','',6);
$pdf->Cell(145,3, "Payment Method : $payment_method", 0,1,'R');
// Transaction ID
$pdf->SetFont('arial','',6);
$pdf->Cell(145,3, "Transaction ID : $transaction_id", 0,1,'R');
if ($method == "display") {
header('Content-type: application/pdf');
header('Content-Disposition: inline; filename="the.pdf"');
header('Content-Transfer-Encoding: binary');
return $pdf->Output();
} else {
return $pdf->Output("$filename", "S");
}
这些行会做什么 - $ pdf = file_get_contents($ data-> file); file_put_contents('rendered_page.pdf',$ pdf); – user4826347
'$ pdf = file_get_contents($ data-> file); '从API获取PDF文件。 'file_put_contents('rendered_page.pdf',$ pdf);'将它保存到文件rendered_page.pdf – Jack