Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am working on a project where a pdf is dynamically created at the node server and needs to be sent to the javascript client where it should open a download prompt on the browser.

I have created the pdf but sending it and receiving it as downloadable is being troublesome.

Following is the code that I have used at the node to send the pdf but it doesn't seems to be right:

    var pdf = fs.readFile("createdPdf/" + uname + "_44.pdf", function() {
        if (pdf == null) {
            res.writeHead(401, {"Content-Type": "text/html"});
            res.write('Failed');
            res.end();  
            return;
        } else {
            res.writeHead(200, {
                "Content-Type": "text/html"
            });
            res.write(pdf);
            res.end();
        }
    });

And I have no idea how to catch this pdf at the javascript client to open the download prompt.

Currently all other responses from the node are being collected as:

var resp_json = printRequest.getResponseJson();

or

var resp_json = printRequest.getResponseText();

Can anyone help me?

P.S. I am using google closure library at the client (don't ask why, company MO).

Thanx in advance!!

share|improve this question
    
Probably more information in his second question: stackoverflow.com/questions/16980323/… –  TheHippo Jun 7 '13 at 12:01

1 Answer 1

up vote 2 down vote accepted

Try adding the Content-Disposition: attachment header, like this:

Content-Disposition: attachment; filename="thePdf.pdf"
share|improve this answer
    
thank u for your answer but i have already taken care of this part. Plz pay a visit to this next question posted by me which is related to this one –  Surender Thakran Jun 7 '13 at 9:10

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.