This is an archived forum post. The information may be outdated. Contact us if you have any questions.

Odd pdf response

ad633 wrote on 2012-03-22:
Hi,
I'm sending raw HTML to the API with an ajax call in JS and I'm getting an odd response.
Not quite sure if I'm doing anything wrong.

Data:
http://pastebin.com/52zpvzxR

My code:
var printPage = function(){
            $.ajax({
                url: 'http://localhost:8080/var/proxy/pdfcrowd/rawhtml.json',
                data: {
                    "src": data,
                    "username": username,
                    "key": apiToken
                },
                type: 'POST',
                success: function(dataResponse){
                    console.log(dataResponse);
                }, error: function(a,b,c) {
                    debug.log(a,b,c);
                }
            });
        };


I'm getting a lot of those unknown things/question marks in the response.
The dataResponse:
http://pastebin.com/MFF8J8s6

Thanks in advance!

Kind regards,
AD
support wrote on 2012-03-22:
Hello,

the response looks correctly, it is a PDF file. Since you are printing the response to a console you are seeing raw PDF data. Try to open any PDF file in a text editor and it will look similarly.
ad633 wrote on 2012-03-23:
Hi,

Thank you for the quick reply.

How would I be able to let the user save this pdf when I receive it with the response?

Kind regards,
AD
support wrote on 2012-03-23:
As far as I know, from security reasons you are not allowed to save data to a local file from Javascript.

One option would be

  1. Create a PDF and store it somewhere on your server
  2. Send the URL of the saved PDF in the ajax response instead of PDF raw data
  3. set document.location.href to the received URL

Another option would be to use a form to post to your server, an example is shown here: https://pdfcrowd.com/forum/archive/read/?3,542,545#msg-545