I have a component (Angular 6) which is an aggregation of several components. This produces a long HTML (I am using Bootstrap 4). Now I want to convert this HTML to PDF. I have searched far and wide and found many solutions that work on jsPDF. The requirement is to produce a crisp layout as it appears in the HTML (so that users can select, copy, etc). But the solutions I found either try to add lines of text manually, which is impossible in my scenario; or they convert (rasterize?) the HTML to image format. Also, I want to preserve the formatting and fonts and styling of my HTML.
Matt Strom
Software Engineer, TypeScript ninja
Do you need the PDF creation to be done programmatically? What about just Print to PDF?
If you need a high level of precision, another option, although older and perhaps involving more complexity than you want, is to use XSL Formatting Objects, or XSL-FO. Given that your HTML is valid XML, you can then use XSL to transform your HTML into Formatting Objects, which in turn is passed into a formatting engine to produce a PDF.
There is a JavaScript project on NPM for doing this named jsx-xsl-fo, though its usage numbers are low. I also doubt you'd be able to do all of this client-side.