7

I'm running an AngularJS app and I'm using the grunt-contrib-connect plugin to host my stuff. I'd like some PDF files to be accessed in the browser (tested in all of them), but the pages stay blank. It does show the correct amount of pages, though. I've exported the PDF from a .doc-file using both Word and Pages, but the result stays the same.

I wrote this little middleware snippet to ensure the headers are set (and they are, according to Chrome's Network tab), but the pages stay blank. Any help?

In my Gruntfile;

grunt.initConfig({
    settings: {}, // ...
    connect: {
        livereload: {
            middleware: function(connect) {
                var middlewares = [];
                // Other middlewares
                middlewares.push(function (req, res, next) {
                    if (~req.url.indexOf('.pdf')) {
                        res.setHeader('Content-type', 'application/pdf');
                    }
                    return next();
                });

                return middlewares;
            }
        } 
    } 
});
Nick
  • 560
  • 6
  • 19
  • I’ve come across this same issue. The PDF document served is quite different from the file in my source, though they both have the same number of pages (5). In my case, when I download and compare the two, the original is 106 KB, while the one I downloaded is 193 KB. And, of course, the one I downloaded is completely blank. – Andrew Patton Jul 17 '14 at 19:08
  • Any news, how to sort it out? – Rootical V. Oct 10 '14 at 13:07
  • possible duplicate of [Why does internet explorer fail to download a PDF using NodeJS and Express?](http://stackoverflow.com/questions/11020374/why-does-internet-explorer-fail-to-download-a-pdf-using-nodejs-and-express) – Paul Sweatte Nov 05 '14 at 16:58

1 Answers1

2

It seems grunt-contrib-connect has problems serving binary files: https://github.com/gruntjs/grunt-contrib-connect/issues/142

geon
  • 8,128
  • 3
  • 34
  • 41