I have a screen where all the information related to user and their tasks will be displayed.. It's like a report. At the end I have a button for the user clicking on which will allow them to save a pdf version of the same information. The information will be different every time.. So the number of rows will be different. How can this be achieved? I tried using react-native-html-to-pdf but I could create pdf of only static html.. Couldn't figure out how to render dynamic html? The ui will be slightly different for the pdf compared to the screen but the information will be same.
From what I see in the post linked above, the following piece of code looks like an html string that you can modify as desired (sync or async regardless):
const printPDF = async () => {
const results = await RNHTMLtoPDF.convert({
html: '<h1>Demo Text to converted to PDF</h1>',
fileName: 'test',
base64: true,
});
await RNPrint.print({filePath: results.filePath});
};
It looks like that text can be dynamically changed, so you can replace it with any function:
const printPDF = async () => {
const htmlString = await buildDynamicHtml();
const results = await RNHTMLtoPDF.convert({
html: htmlString,
fileName: 'test',
base64: true,
});
await RNPrint.print({filePath: results.filePath});
};