Skip to content

How to render AND download on link clink, without rendering on page load #2031

Answered by coskuncakir
mn-prp asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @mn-prp,

I achieved what you want using a third-party file saver to save the current blob data we can get from react-pdf's pdf method,

so basically you could do something like below

import { saveAs } from 'file-saver'
import { pdf } from '@react-pdf/renderer'

const Download = () => {
  const handleDownload = async () => {
    const blob = await pdf(<YourDocument />).toBlob()
    saveAs(blob, 'untitled.pdf')
  }

  return <button onClick={handleDownload}>Download</button>
}

export default Download

let me know how it goes,
cheers

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@mn-prp
Comment options

Answer selected by mn-prp
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants