-
-
Notifications
You must be signed in to change notification settings - Fork 890
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from wojtekmaj/change/support-objects-as-parame…
…ters Change/support objects as parameters
- Loading branch information
Showing
6 changed files
with
190 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,32 @@ | ||
react-pdf | ||
========= | ||
# React-PDF | ||
Easily display PDF files in your React application. | ||
|
||
What is react-PDF? | ||
---- | ||
|
||
A component for displaying PDF files using [pdf.js](http://mozilla.github.io/pdf.js). | ||
|
||
Demo | ||
----- | ||
## tl;dr | ||
* Install by executing `npm install --save react-pdf`. | ||
* Import by addding `import ReactPDF from 'react-pdf'` | ||
* Use by adding `<ReactPDF file="..." />`. `file` can be an URL, base64 content, Uint8Array, and more. | ||
|
||
## Demo | ||
Demo page is included in sample directory. | ||
|
||
[Online demo](http://projekty.wojtekmaj.pl/react-pdf/) is also available! | ||
|
||
Usage | ||
----- | ||
## Getting started | ||
### Prerequisites | ||
|
||
You'll need to have Node >= 4 on your machine. | ||
|
||
We strongly recommend to use Node >= 6 and npm >= 3 for faster installation speed and better disk usage. | ||
|
||
Your project needs to use React 15.0.0 or later. | ||
|
||
### Installation | ||
|
||
Install with `npm install --save react-pdf` | ||
Add React-PDF to your project by executing `npm install --save react-pdf`. | ||
|
||
Use in your app: | ||
### Usage | ||
|
||
Here's an example of basic usage: | ||
|
||
```js | ||
import ReactPDF from 'react-pdf'; | ||
|
@@ -48,16 +56,32 @@ class MyApp extends React.Component { | |
} | ||
``` | ||
Check the sample drectory of this repository for a full working example. | ||
Check the sample directory of this repository for a full working example. | ||
License | ||
------- | ||
## User guide | ||
The MIT License | ||
### Props | ||
|Prop name|Description|Example of usage| | ||
|----|----|----| | ||
|file|Defines what PDF should be displayed.<br />Its value can be an URL, a file (imported using `import ... from ...` or from file input form element), or an object with parameters (`url` - URL; `data` - data, preferably Uint8Array; `range` - PDFDataRangeTransport; `httpHeaders` - custom request headers, e.g. for authorization).|<ul><li>URL:<br />`file="http://example.com/sample.pdf"`</li><li>File:<br />`import sample from '../static/sample.pdf'` and then<br />`file={sample}`</li><li>Parameter object:<br />`file={{ url: 'http://example.com/sample.pdf', httpHeaders: { 'X-CustomHeader': '40359820958024350238508234' }}}`</ul>| | ||
|loading|Defines what the component should display while loading. Defaults to "Loading PDF…".|<ul><li>String:<br />`loading="Please wait!"`</li><li>React element:<Br />`loading={<div>Please wait!</div>}`</li><li>Function:<Br />`loading={this.renderLoader()}`</li></ul>| | ||
|error|Defines what the component should display in case of an error. Defaults to "Failed to load PDF file.".|<ul><li>String:<br />`error="An error occurred!"`</li><li>React element:<Br />`error={<div>An error occurred!</div>}`</li><li>Function:<Br />`error={this.renderError()}`</li></ul>| | ||
|pageIndex|Defines which page from PDF file should be displayed. Defaults to 0.|`pageIndex={2}`| | ||
|scale|Defines the scale in which PDF file should be rendered. Defaults to 1.0.|`scale={0.5}`| | ||
|onDocumentLoad|Function called when the document is successfully loaded to the memory.|`onDocumentLoad={({ total }) => alert('Loaded a file with ' + total + ' pages!')}`| | ||
|onDocumentError|Function called in case of an error while loading a document.|| | ||
|onPageLoad|Function called when the page is successfully loaded to the memory.|`onPageLoad={({ pageIndex, pageNumber }) => alert('Now displaying a page number ' + pageNumber + '!')}`| | ||
|onPageRender|Function called when the page is successfully rendered on the screen.|`onPageLoad={() => alert('Rendered the page!')}`| | ||
|onPageError|Function called in case of an error while rendering a page.|| | ||
Author | ||
------ | ||
## License | ||
The MIT License | ||
Wojciech Maj <[email protected]> | ||
## Author | ||
Wojciech Maj<br /> | ||
<[email protected]><br /> | ||
[wojtekmaj.pl](http://wojtekmaj.pl) | ||
Based on an awesome work of Niklas Närhinen <[email protected]> | ||
This project wouldn't be possible without awesome work of Niklas Närhinen <[email protected]> who created its initial version and without Mozilla, author of [pdf.js](http://mozilla.github.io/pdf.js). Thank you! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.