gpt4 book ai didi

php - 使用 php 将生成的输出 html/css 转换为 pdf - 2017 年

转载 作者:行者123 更新时间:2023-11-28 03:33:20 25 4
gpt4 key购买 nike

我生成如下所示的 php 输出

$.fn.getPDF = function(folder_suffix){
var fullurl = folder_suffix+"/superimpressivereport.php";
$.ajax({
url: fullurl,
dataType:'html'
}).done(function(data) {
$.fn.converthtmltopdf(data):
});
};
$.fn. fn.converthtmltopdf = function(htmlcssoutput){
//TODO
}

我想将使用 bootstrap 和 css 生成的输出 html 转换为整洁的 pdf 文件。有没有我可以用来动态生成 pdf 的库,以便用户可以在他们的本地计算机上生成和下载 pdf 文件?

非常感谢!

最佳答案

您不能在 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");
}

关于php - 使用 php 将生成的输出 html/css 转换为 pdf - 2017 年,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44603708/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com