我想创建一个使用FPDF PDF文件。
I am trying to create pdf file using FPDF.
我现在已经是各种线数据和它旁边的打印按钮的HTML页面。当有人点击打印,我通过AJAX调用发送使用jQuery相应的数据。
What I right now have is an HTML page with various lines of data and a print button next to it. When someone clicks Print, I am sending corresponding data using Jquery by making AJAX call..
这是我的JQUERY code:
This is my JQUERY code:
$('.printbtn').live('click', function(){
var printdata = 'name=' + name_t + '&address=' + address_t;
$.post('print.php', printdata, function(){
});
return false;
});
这是print.php
this is print.php
$name = $_POST['name'];
$address = $_POST['address'];
require ("fpdf17/fpdf.php");
$pdf = new FPDF('P','mm',array(90,100));
$pdf->AddPage();
$pdf->SetFont('Arial','B',12);
$pdf->Cell(0,10,'name: '.$name);
$pdf->Cell(0,10,'address: '.$address);
$pdf->Output();
?>
不过,我没有得到PDF的回报。怎么了??事实上,没有任何事情发生.. 我想中检索的PDF文件,并把它打印
But I am not getting PDF in return. Whats wrong?? In fact, nothings happening.. I want to retreive the pdf file and send it to print
推荐答案
要通过AJAX,你可以尝试加载PDF:
To load a PDF via ajax you could try:
使用某些PDF JavaScript库,从直接呈现的PDF JavaScript的无插件,如 Mozilla的pdf.js 或的 jspdf 。 并尝试看看这些库让你直接从设置PDF 二进制数据(你在阿贾克斯获得什么的)。
Use some of the PDF javascript libraries to render PDF directly from javascript without plugins, like mozilla pdf.js or jspdf . And try to see if those libraries let you set the pdf directly from binary data (what you receive in ajax).
另一种选择是接受PDF数据为base64 EN codeD和使用
一个数据URI 来设定 window.location.href
来该数据的URI,
虽然在这种情况下,有可能将PDF是作为一个下载中心
对话,而不是直接在页面加载,你必须测试
那。另外数据URI支持是非常在IE 8的限制对PDF和
年纪大了,看维基百科数据URI 页面了解更多详情。
Another option is receive the pdf data as base64 encoded and the use
a Data URI to set window.location.href
to that data uri,
although in that case it's possible the PDF is offered as a dowload
dialog instead of loading directly in the page, you have to test
that. Also data uri support is very limited for pdf in IE 8 and
older, see the wikipedia data uri page for more details.
另请参见这个答案它是如何不可能加载PDF
直接从AJAX和什么其他选择,你必须尝试做什么
你想要的(主要是节省了PDF作为临时文件在服务器上,并用它
与 window.location.href
或< IFRAME>
或的window.open
)
Also see this answer about how it's not possible to load pdf
directly from ajax and what other options you have to try to do what
you want (mainly saving pdf as temporary file on server and use it
with window.location.href
or <iframe>
or window.open
)
相关推荐
最新文章