0.9.3 • Published 6 months ago

document-preview-react v0.9.3

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

React Document Preview

A React component for rendering previews of PDF documents, Word documents, and images with thumbnail generation support.

Installation

npm install react-document-preview
# or
yarn add react-document-preview

Features

  • Supports PDF, Word documents, and image previews
  • Generates thumbnails for PDF and Word documents
  • Customizable dimensions
  • Loading states and error handling
  • Download button for documents
  • Responsive design

Usage

import { DocumentPreview } from 'react-document-preview';

function App() {
  return (
    <DocumentPreview
      url="https://example.com/document.pdf"
      width={300}
      height={210}
      documentType="pdf"
    />
  );
}

Props

PropTypeDefaultDescription
fileFile \| nullundefinedFile object for local document preview
urlstringundefinedURL of the document to preview
widthnumber300Width of the preview container
heightnumber210Height of the preview container
documentType"pdf" \| "image" \| "word"RequiredType of document being previewed

Examples

PDF Preview

// Preview PDF from URL
<DocumentPreview
  url="https://example.com/document.pdf"
  documentType="pdf"
/>

// Preview PDF from File object
<DocumentPreview
  file={pdfFile}
  documentType="pdf"
/>

Word Document Preview

<DocumentPreview
  url="https://example.com/document.docx"
  documentType="word"
/>

Image Preview

<DocumentPreview
  url="https://example.com/image.jpg"
  documentType="image"
/>

Custom Styling

The component comes with default styling but can be customized using the styles object:

const customStyles = {
  container: (width: number, height: number) => ({
    width,
    height,
    borderRadius: 12,
    outline: "2px solid dodgerblue",
    // Add your custom styles here
  }),
};

Dependencies

  • React 16.8+
  • pdfjs-dist
  • lucide-react

Browser Support

  • Chrome (latest)
  • Firefox (latest)
  • Safari (latest)
  • Edge (latest)

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT © Nitin Jaswal

0.9.3

6 months ago

0.9.0

6 months ago

0.9.2

6 months ago

0.8.0-test.1

6 months ago

0.7.9

6 months ago

0.7.6

6 months ago

0.7.5

6 months ago

0.7.8

6 months ago

0.7.7

6 months ago

0.7.6-test

6 months ago

0.7.9-test.0

6 months ago

0.8.0-test.0

6 months ago

0.7.7-test

6 months ago

0.7.3-development

6 months ago

0.7.2-development

6 months ago

0.7.1-development

6 months ago

0.7.0-development

6 months ago

0.6.0-development

6 months ago

0.5.0-development

6 months ago

0.0.0-development

6 months ago