react-pdf-to-image

1.0.2 • Public • Published

react-pdf-to-image

A a render prop component wrapper around pdf.js that asynchronously converts PDF files into data URLs in the browser.

Example Usage

import React from 'react';
import {PDFtoIMG} from 'react-pdf-to-image';
import file from './pdf-sample.pdf';

const App = () =>
    <div>
        <PDFtoIMG file={file}>
            {({pages}) => {
                if (!pages.length) return 'Loading...';
                return pages.map((page, index)=>
                    <img key={index} src={page}/>
                );
            }}
        </PDFtoIMG>
    </div>

export default App;

Issues

  • Relies on the pdf.js distribution from Mozilla which uses a web worker. Currently in order to get this working in webpack development mode you must add globalObject: 'this' to the output options in webpack.config.js. If you're using create-react-app then currently the only option is to eject and add that to your config. Otherwise builds will work fine but webpack-dev-server will not.

  • Not optimized for loading very large multi-page PDFs and works best when used to convert simple single page documents to Image URLs

  • POC atm so there's no tests or error handling.

Package Sidebar

Install

npm i react-pdf-to-image

Weekly Downloads

733

Version

1.0.2

License

none

Unpacked Size

782 kB

Total Files

9

Last publish

Collaborators

  • marcaaron