Download
Save the open document under a sensible file name without requesting it again, or take over the download yourself.
Basics
The download button saves the bytes that are already loaded, so authenticated or expiring URLs are never requested twice.
The file name is fileName when you pass one; otherwise a File’s name, the last .pdf segment of the URL, or document.pdf.
Intercepting the download
onDownload receives { fileName, data } before anything is saved. Return false to handle the bytes yourself.
If saving fails, onError receives a DOWNLOAD_FAILED error; see Error states.
Customization
Set the file name, rename the button, and choose which toolbar actions appear.
See the customization guide.
Advanced / escape hatch
download() on the imperative API starts the same download from your own button. getDocument() returns the PDF.js document if you need its getData() for something other than saving.
Limitations
- The original file is saved. Rotation, zoom and search highlights are not written into the download. Workaround: none within the viewer; post-process the bytes from
onDownloadwith a PDF library if you need a modified file. - Some mobile browsers open instead of saving. iOS Safari may show the PDF in a new view rather than a download prompt; this is browser behavior. Workaround: none reliable; the user can share or save from there.
API
PdfViewerProps— Props for PdfViewer. Every piece of state supports the value / defaultValue / onChange trio.