0

im creating a service that will transform html to pdf. Request with parameter(HTML code to be transfered into PDF) ist send with ajax post.

On server side generating pdf file is no problem. I was trying to send it back with JSON but i figured out that its not a good idea. So now im sending it back with no changes - full pdf file as it was generated

...
$pdf->Output('out.pdf', 'I');

And here comes the tricky part. What can i do with it on client side? I was trying to show it or download it but i could not figured out how.

$.ajax({
        type: 'POST',
        url: service_url,
        data: out,
        success: function (data) {
        // WHAT SHOULD I DO WITH "data" IF I WANT TO SHOW IT?
        error: function () {
           alert("Error");
        }
    });

Thanks

Oscar LT
  • 787
  • 1
  • 4
  • 24

1 Answers1

0

a wild guess would say that you need to create a PDFObject and then throw it into the Ajax.

HTML

<object id="pdf" data="myfile.pdf" type="application/pdf" width="100%" height="100%">

It appears you don't have a PDF plugin for this browser. No biggie... you can click here to download the PDF file.

</object>

and in the Ajax you would have to do something like :

$.ajax({
    var pdf = $("#pdf");
    type: 'POST',
    url: service_url,
    data: out,
    success: function (data) {
     pdf.show();
    error: function () {
       alert("Error");
    }
});
Jonathan Meguira
  • 1,860
  • 2
  • 12
  • 15