Rendering as pdf is usually a pain, but there is a way around this using canvas.
The idea is to convert: HTML → Canvas → PNG (or JPEG) → PDF
To achieve the above, you will need:
- html2canvas &
- jsPDF
import React, {Component, PropTypes} from 'react';
The snippet will not work here because the necessary files are not imported.
This answer uses an alternative approach when the middle steps are omitted and you can simply convert from HTML to PDF. It is possible to do this in the jsPDF documentation, but from personal observation, I feel that the best accuracy is achieved when converting dom to png for the first time.
Update 0: September 14, 2018
Text in PDF files created using this approach will not be selected. If this is a requirement, you may find this article helpful.
source share