2017-06-17 6 views
0

は、私はきちんとしたPDFファイルにブートストラップとCSSを使用して生成された出力HTMLを変換したい次変換生成された出力HTML/CSSのPDFファイルにPHPを使用して - 年2017

$.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 
} 

のようなPHPの出力を生成します。ユーザーが自分のローカルコンピュータでpdfファイルを生成してダウンロードできるように、pdfをオンザフライで生成するために使用できるライブラリはありますか?

ありがとうございます!あなたは、PDFのためのJavascript でこれを行うことはできません

答えて

0

は、あなたが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"); 
} 
0
あなたのAJAXで

あなたはPHPスクリプトを呼び出すことができますし、このPHPの内側にこのコードを置くことができます。

<?php 
$url = 'http://example.com/document.html'; 
$data = json_decode(file_get_contents('http://api.rest7.com/v1/html_to_image.php?url=' . $url . '&format=pdf')); 

if (@$data->success !== 1) 
{ 
    die('Failed'); 
} 
$pdf = file_get_contents($data->file); 
file_put_contents('rendered_page.pdf', $pdf); 

この例は、HTMLファイルへのURLを使用していますPHPでCURL拡張を使用してHTTP POSTを実行することができますhttp://api.rest7.com/v1/html_to_image.php

+0

これらの行は何をしますか? - $ pdf = file_get_contents($ data-> file); file_put_contents( 'rendered_pa​​ge.pdf'、$ pdf); – user4826347

+0

'$ pdf = file_get_contents($ data-> file); 'はAPIからPDFファイルを取得します。 'file_put_contents( 'rendered_pa​​ge.pdf'、$ pdf);'それがレンダリングされたファイルをrendered_pa​​ge.pdfに保存します。 – Jack

関連する問題