I am using @react-pdf/render in my react js website. I am getting HTML code form backend as a string and I want to render it as HTML in react-pdf. Please suggest me a solution or I should use some other library?
Asked
Active
Viewed 1,660 times
1
-
This might help [link](https://stackoverflow.com/questions/39758136/render-html-string-as-real-html-in-a-react-component). Try to use [dangerouslySetInnerHTML](https://reactjs.org/docs/dom-elements.html#dangerouslysetinnerhtml) – Danko Mar 27 '20 at 10:28
-
in react-pdf how can I use it? – Kirti Nirkhiwale Mar 27 '20 at 10:59
-
Can you create simplified example on https://codesandbox.io/ where you will have `react-pdf/render` installed and string you want to render - already fetched? Share url here and I will take a look. – Danko Mar 27 '20 at 11:03
-
[https://codesandbox.io/s/filesaver-8mm3o – Kirti Nirkhiwale Mar 27 '20 at 12:13
-
1Just have tried and it appears that lib doesn't support using html tags: "Invalid element of type div passed to PDF renderer". Only [these components](https://react-pdf.org/components) can be used. If your pdf is not super complex, you might consider fetching json which will only have text/string values like { docId: "..", pageTitle: "..", sections: [{section1: {heading: '..', text: ''..'}}, {section2: {heading: '..', text: ''..'}}]}... – Danko Mar 27 '20 at 12:41
-
My Pdf is complex. I am getting html from backend @Danko – Kirti Nirkhiwale Mar 27 '20 at 13:40
-
I see. Is generating pdf on server-side an option for you? If it's not, just have found [this article](https://itnext.io/javascript-convert-html-css-to-pdf-print-supported-very-sharp-and-not-blurry-c5ffe441eb5e) and it looks promising to me (haven't used this approach by myself) – Danko Mar 27 '20 at 14:37
-
I have tried this solution also but it is having pdf blur issue – Kirti Nirkhiwale Mar 27 '20 at 14:48
-
@KirtiNirkhiwale I have the same issue. Do you have the solution? – hotcakedev Feb 04 '21 at 16:51