SERVER-SIDE PDF GENERATION AND ANGULAR $RESOURCE I ran into a problem recently where my Angular application needed to consume an API call that returned a PDF response. Apparently there are options to generate PDF documents client-side, such as Mozilla's PDF.js , but in this case I had no control over the data. The scenario looked like this: Send a HTTP request with an Accept header of application/pdf and expect to recieve a PDF byte-stream response. Allow the user to download this PDF from their browser after making the call. I had no access to the server in this scenario since my Angular application is stateless and relies primarily on ngResource to consume external API payloads. I simply wanted the user to click a "Download PDF" button and have the browser prompt them to download the file. I managed to accomplish this by adding a new method to the ngResource object: pdf: { method: 'GET' , headers: { accept: 'application/pdf...
Comments
Post a Comment