@react-pdf-viewer/get-file
TypeScript icon, indicating that this package has built-in type declarations

3.12.0 • Public • Published

download plugin

This plugin allows user to download the current file.

import { downloadPlugin } from '@react-pdf-viewer/download';

const downloadPluginInstance = downloadPlugin();

// The button to download the current file
const { Download } = downloadPluginInstance;

// Render
return (
    <>
    <Download />
    <Viewer
        plugins={[
            downloadPluginInstance,
        ]}
    >
    </>
);

Use a custom button

import { downloadPlugin } from '@react-pdf-viewer/download';

const downloadPluginInstance = downloadPlugin();

// The button to download the current file
const { Download } = downloadPluginInstance;

// Render
return (
    <>
    <Download>
    {
        (props) => (
            // Your custom button here
            <button onClick={props.onClick}>
                Download
            </button>
        )
    }
    </Download>
    <Viewer
        plugins={[
            downloadPluginInstance,
        ]}
    >
    </>
);

Plugin options

  • fileNameGenerator (Optional): Custom the name of download file.

It is a function accepts the current opened file and returns a string:

(file: OpenFile) => string;

By default, the name of download file is determined by the name properties of OpenFile. You can customize it as following:

import { OpenFile } from '@react-pdf-viewer/core';

const downloadPluginInstance = downloadPlugin({
    fileNameGenerator: (file: OpenFile) => {
        // `file.name` is the URL of opened file
        const fileName = file.name.substring(file.name.lastIndexOf('/') + 1);
        return `a-copy-of-${fileName}`;
    },
});

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
3.12.0125,573latest

Version History

VersionDownloads (Last 7 Days)Published
3.12.0125,573
3.11.02,076
3.10.0402
3.9.0294
3.8.0312
3.7.02,083
3.6.02,397
3.5.045
3.4.092
3.3.334
3.3.257
3.3.17
3.3.079
3.2.0197
3.1.26
3.1.16
3.1.018
3.0.048
2.11.01,000
2.10.1137
2.10.063
2.9.1161
2.9.0100
2.8.021
2.7.219
2.7.133
2.7.00
2.6.10
2.6.07
2.5.0101
2.4.3119
2.4.2198
2.4.159
2.4.050
2.3.29
2.3.10
2.3.03
2.2.19
2.2.00
2.1.01
2.0.10
2.0.00

Package Sidebar

Install

npm i @react-pdf-viewer/get-file

Weekly Downloads

135,816

Version

3.12.0

License

https://react-pdf-viewer.dev/license

Unpacked Size

15.4 kB

Total Files

7

Last publish

Collaborators

  • phuoc-ng