Handle pdf download in React.js
<div className="formRow float-right-no-margin">
{this.props && this.props.file && this.props.file.length > 0 && (
<Button variant="primary" onClick={handlePdfDownload}>
Download
</Button>
)}
<Button variant="secondary" onClick={this.props.handlePreviewClose}>
Close
</Button>
</div>
const handlePdfDownload = () => {
// Insert a link that allows the user to download the PDF file
var link = document.createElement('a');
link.innerHTML = 'Download PDF file';
link.download = this.props.fileName;
link.href = this.props.file;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
};
//hide Modal
handlePreviewClose = () => {
this.setState({ showPreview: false, pageNumber: 1 })
};
No comments:
Post a Comment