Prav
Prav

Reputation: 63

Blank PDF with Express Request

I am getting a blank pdf when viewing in the browser and the request works because every time i search for a different pdf (localhost:3001/sample.pdf) the page numbers change, i have seen many questions asked about this and I have tried all their advice (base64 stuff, Buffer.from stuff, content-type app/pdf stuff), still haven't got it working.

app.get('/:file', function(req, res) {
    request('http://host/path/' + req.params.file, function(error, response, body) {
       res.end(body);
    });    
}).listen(port);

pls point me in right direction!

Upvotes: 1

Views: 1612

Answers (2)

Kumar Shanoo
Kumar Shanoo

Reputation: 135

Explore the metadata values of the PDF.Specifically Xref tables .If Xref tables is corrupted somehow the pdf application will not be able to resolve the objects inside the file and file will open as blank.

Upvotes: -1

jfriend00
jfriend00

Reputation: 707158

You aren't sending a properly defined response that has proper headers, content-type and matching encoded data. Since the server you are fetching the PDF from has already done that for you, I'd suggest you just .pipe() the response directly.

app.get('/:file', function(req, res) {
    request('http://host/path/' + req.params.file).pipe(res);    
}).listen(port);

Upvotes: 3

Related Questions