0

I'm trying to display by jquery load() a dynamically generated PDF created by PHP with FPDFlib on a div but what I get is a jam of chars. Is there a way to resolve it?

thanks in advance

I've tried to correct my code in this way but continue to display jam

    $.post("./php/stampa_login.php",
    {piatta:'<? echo $_POST["piatta"] ?>'}, 
    function(data){
        $("#stampa_content").load("./temp/login.pdf")
});

ciao

h.

1
  • can we see your code please, seems like an output issue. Commented Sep 15, 2010 at 17:37

4 Answers 4

1

That seems to be correct. jQuery's load() fetches an URL through AJAX; if that URL is PDF, it appears as "jam of chars" to the browser, as PDF and HTML aren't compatible at all, the formats are completely different.

What you probably want is to open the PDF as an <object>, but then you're hoping that the user has some PDF plugin installed in their browser. Let's take a step back: what are you trying to achieve here, by displaying a PDF?

Sign up to request clarification or add additional context in comments.

1 Comment

I load by JQuery php page that generate PDF; I suppose that this is the problem, may be I can resolve amkeing a post request to php page that generate PDF, save it in local and after load for display...
1

You can create a blank embed tag and give src attribute as link. in your call back function. This will load the pdf file perfectly.

 $("#embed_tag_id").attr("src", "./temp/login.pdf");

Comments

1

Instead of using $("#whatever").load();

You'll want something like this:

$("#stampa_content").html ($("<object>", {
  data : "./temp/login.pdf",
  type : "application/pdf",
  width : 800,
  height : 600
}));

What that will do is instead of trying to load the contents of the PDF into a DIV, it will create an <object> block that will start up your PDF reader (such as Adobe Reader) which will then load the PDF itself and display it.

Comments

0

ya, seems to be an output issue. Have you tried header function to output it correctly ? try for proper output or instead of opening the pdf in div, just update the pdf's link there

2 Comments

I use these headers: header('Accept-Ranges: bytes'); header("Content-type: application/pdf");
I don't think that this will work. You will have to update the div with the link for the newly generated pdf.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.