Reputation: 7
I had a requirement in that pdf needs to be open in new tab but download should be restricted for some users.
I've came across few third packages on react none worked out well even rendering pdf file even If I can I need to have a provision to open pdf file or docs or excel. Help me out! Thanks in advance!
Upvotes: -1
Views: 1127
Reputation: 419
To open pdf in new tab:
<a href='/api/v1/print/example.pdf' target='_blank' rel='noopener noreferrer'>
Then use some conditional logic in the component to disable download if the user is not authenticated.
renderDownloadLink() {
if (this.state.isAuthenticated) {
return (
<a href="/path/to/your-pdf.pdf" download>
Download PDF
</a>
);
} else {
return (
<p>You must be authenticated to download the PDF.</p>
);
}
}
Upvotes: 0