My current architecture:
- Two backends - one C# and one Python/Flask - providing JSON-based data to a front-end application.
- Front-end application written in AngularJS 1.6.
- Reports being generated from Angular views - dynamically generated with AngularJS's data binding.
- CSS hacks being used to make output suitable for printing. (On-screen view is pretty bad though.)
- Authentication is via bearer token using OAuth - credentials are provided to a backend endpoint which generates a token that is then provided with each request.
What I'd like to do:
- Transition to a mode where reports are generated and delivered to the user as a PDF file. This could be done either on the frontend or the backend, but the backend seems like it'd be a more appropriate place - not to mention, doing it on the frontend could bring the same issues I'm already having with CSS hacks.
- The generated PDF files must be able to have a repeating header and footer, both of which may contain dynamic data (e.g. page numbers in the footer, client name in the header)
- PDF downloads need to be authenticated. (It should not be possible to request a PDF without some backend code being run to ensure the request is approved)
- PDF authentication must be able to integrate with the OAuth bearer token authentication already being used by the app (C# backend generates a bearer token. Python backend currently is only serving non-private data, but we could do a dual-login scenario where both APIs generate their own tokens.)
Here's my challenges:
- For some reason browsers do not support
@pageCSS even when printing a webpage. Therefore, I cannot include headers or footers. Not to mention each browser may render the content slightly differently. Generating PDF on the backend will unify the reports.
- Since the reports are currently dynamically generated on the frontend using AngularJS, I would probably have to change how this is done in order for the backend to be able to self-generate PDF files. I'm not sure where to start with this, other than maybe writing a C# class that can hand-generate the HTML - you won't have all the beauties of Angular data binding and ease of changing the template as needed though. I'd like this transition to be as smooth as reasonably possible.
- Is there a good free (open-source preferable, freeware OK, paid last-resort and within reason as this is a personal project which will only be used by maybe 3 people) library that can generate PDF from HTML/CSS on the backend and that can work within my environment of OAuth token authentication?
- What would be the best approach to generate the HTML for reports on the backend without the help of AngularJS data binding? Manual HTML generation in CSS/Python? Some other data binding framework that's designed for backend (not sure if that exists)?