我正在與這個發票頁面上的文本框用戶輸入數字到他們的訂單。現在我在Windows 7操作系統上使用wamp,並且在用戶輸入數字後將其轉換爲pdf並將其保存在一個文件夾中,然後將其輸出到另一個窗口進行查看。如何安裝wkhtmltopdf wamp與Windows 7操作系統
到目前爲止,我還沒有能夠做得太多,這讓我在過去的兩週內瘋狂起來。請,我需要建議,真的很感激。
這裏是我想要的,需要做的:
- 保存,因爲它是在HTML包括在文本框中的值的頁面。
- 將保存的頁面轉換爲pdf並存儲在目錄中。
- 將該pdf發送給用戶。
代碼到目前爲止
頁面保存HTML
function printPDF() { var h = '<style></style>'+$('#article').html(); var html = '<html><body><scr'+'ipt>'; html += 'var form = document.createElement("form");'; html += 'form.setAttribute("method","post");'; html += 'form.setAttribute("action","/ajax/pdf/");'; html += 'var h = document.createElement("input");'; html += 'h.setAttribute("type","hidden");'; html += 'h.setAttribute("name","html");'; html += 'h.setAttribute("value","'+escape(h)+'");'; html += 'form.appendChild(h);'; html += 'document.body.appendChild(form);'; html += 'form.submit();'; html += '</sc'+'ript></body></html>'; var w = window.open('',''); w.document.write(html); w.document.close(); }
但問題是,這有可能打開一個新的窗口,每次和我不想要,我想它通過ajax/jquery在後臺提交,其次創建的html文件沒有在文本框中的值,他們都清除。
轉換到PDF和存儲在目錄
$filepath = '/www/html/'; $pdfpath = '/www/pdf/'; $filename = date('YmdHisu'); $html = urldecode($_POST['html']); file_put_contents($filepath.$filename.'.html',$html); $pdfcmd = 'wkhtmltopdf.sh '.$filepath.$filename.'.html '.$pdfpath.$filename.'.pdf --disable-javascript'; exec($pdfcmd); if ($fd = fopen($pdfpath.$filename.'.pdf','r')) { $fsize = filesize($pdfpath.$filename.'.pdf'); header('Content-type: application/pdf'); header('Content-length: '.$fsize); header('Cache-control: private'); while(!feof($fd)) { $buffer = fread($fd, 2048); echo $buffer; } fclose($fd); } unlink($filepath.$filename.'.html');
也有使用的包裝我得到了wkhtmltopdf但沒有一個似乎工作
真的需要所有這些大寫字母嗎?有點感覺就像你在向我們大喊:P – Lix
但是@bol - 這些是整個帖子中只有**的大寫字母! ;) – Lix
@Lix:這就是爲什麼參數是'$ title'而不是'$ post' :) – BoltClock