Hi - I have the framework of a custom component that will generate a PDF based on some HTML and CSS.
<style>
body {
margin: 0;
}
</style>
<script src="https://cdn.tryretool.com/js/react.production.min.js" crossorigin></script>
<script src="https://cdn.tryretool.com/js/react-dom.production.min.js" crossorigin></script>
<script src="https://unpkg.com/@material-ui/core@3.9.3/umd/material-ui.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2pdf.js/0.10.1/html2pdf.bundle.min.js"></script>
<div id="react"></div>
<script type="text/babel">
const { Button, Card, CardContent } = window["material-ui"];
const MyCustomComponent = ({ triggerQuery, model, modelUpdate }) => (
<Card>
<CardContent>
<div>{model.displayText}</div>
<Button
color="primary"
variant="outlined"
onClick={() => triggerQuery(model.queryToTrigger)}
>
Trigger {model.queryToTrigger}
</Button>
<Button
color="primary"
variant="outlined"
onClick={() =>
modelUpdate({ displayText: "much custom, such flexibility. wow." })
}
>
Update Model
</Button>
</CardContent>
</Card>
);
const ConnectedComponent = Retool.connectReactComponent(MyCustomComponent);
ReactDOM.render(<ConnectedComponent />, document.getElementById("react"));
</script>
I need to call the following function from a button click (essentially replacing the current code for the onClick event)
function pdprint() {
var opt = {
margin: 0.5,
filename: 'myfile.pdf',
image: { type: 'jpeg', quality: 0.98 },
html2canvas: { scale: 2 },
jsPDF: { unit: 'in', format: 'letter', orientation: 'portrait' }
};
window.html2pdf().set(opt)
.from(document.getElementById("react"))
.toPdf()
.output('bloburl')
.then(function(pdfas) { window.open(pdfas) } );
}
but I can't for the life of me work out the correct syntax to call the function, or placement of the function in the code. Is anyone able to help please...?
Thanks
Adam