Skip to content

Commit

Permalink
Super basic new library working
Browse files Browse the repository at this point in the history
  • Loading branch information
mikecousins committed Jun 12, 2018
1 parent b8e1200 commit 85b03c6
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 21 deletions.
Binary file added example/public/test.pdf
Binary file not shown.
4 changes: 2 additions & 2 deletions example/src/App.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React, { Component } from 'react'

import ExampleComponent from 'react-pdf-js'
import Pdf from 'react-pdf-js'

export default class App extends Component {
render () {
return (
<div>
<ExampleComponent text='Modern React component module' />
<Pdf file='test.pdf' />
</div>
)
}
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
"predeploy": "cd example && yarn install && yarn run build",
"deploy": "gh-pages -d example/build"
},
"dependencies": {},
"dependencies": {
"pdfjs-dist": "2.0.550"

This comment has been minimized.

Copy link
@MichaelDeBoey

MichaelDeBoey Jun 12, 2018

Contributor

I think it's best to make this a caret (^) like

  "pdfjs-dist": "^2.0.550"

This comment has been minimized.

Copy link
@mikecousins

mikecousins Jun 12, 2018

Author Owner

No, they break stuff all the time and we have a fixed version number in the worker reference. I wish I could but they don't bump major versions enough.

This comment has been minimized.

Copy link
@MichaelDeBoey

MichaelDeBoey Jun 12, 2018

Contributor

Have to keep the dependency up to date by ourselves then 🙂

This comment has been minimized.

Copy link
@MichaelDeBoey

MichaelDeBoey Jun 15, 2018

Contributor

If you follow along with mozilla/pdf.js#9440, you'll see that pdfjs-dist is still in 1.x release and the 2.x isn't officially released yet.
When this is done (will be soon), we'll be able to just use the caret (^) in our package.json 🙂

This comment has been minimized.

Copy link
@mikecousins

mikecousins Jun 15, 2018

Author Owner

The other problem is the worker, as you see we have a hardcoded version in there. Need to do something fancy to get that problem resolved as well.

},
"peerDependencies": {

This comment has been minimized.

Copy link
@MichaelDeBoey

MichaelDeBoey Jun 12, 2018

Contributor

All current peerDependencies should be normal dependencies, and webpack should be a peerDependency, since it's a peerDependency of pdfjs-dist

This comment has been minimized.

Copy link
@wojtekmaj

wojtekmaj Jun 26, 2018

This comment has been minimized.

Copy link
@MichaelDeBoey

MichaelDeBoey Jun 27, 2018

Contributor

I was already thinking there should be something wrong, but just added de peerDependencies according to the current dependencies that’s all...

"prop-types": "^15.5.4",
"react": "^15.0.0 || ^16.0.0",
Expand Down
41 changes: 26 additions & 15 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,37 @@
/**
* @class ExampleComponent
* @class ReactPdfJs
*/

import React, { Component } from 'react'
import PropTypes from 'prop-types'
import PdfJsLib from 'pdfjs-dist';

import styles from './styles.css'

export default class ExampleComponent extends Component {
export default class ReactPdfJs extends Component {
static propTypes = {
text: PropTypes.string
file: PropTypes.string
}

render() {
const {
text
} = this.props
componentDidMount() {
PdfJsLib.GlobalWorkerOptions.workerSrc = '//cdnjs.cloudflare.com/ajax/libs/pdf.js/2.0.550/pdf.worker.js';
PdfJsLib.getDocument(this.props.file).then((pdf) => {
pdf.getPage(1).then((page) => {
var scale = 1.5;
var viewport = page.getViewport(scale);

var canvas = document.getElementById('pdf-canvas');
var context = canvas.getContext('2d');
canvas.height = viewport.height;
canvas.width = viewport.width;

var renderContext = {
canvasContext: context,
viewport: viewport
};
page.render(renderContext);
});
});
}

return (
<div className={styles.test}>
Example Component: {text}
</div>
)
render() {
return <canvas id="pdf-canvas" />;
}
}
31 changes: 28 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ ajv-keywords@^2.0.0, ajv-keywords@^2.1.0:
version "2.1.1"
resolved "https://registry.yarnpkg.com/ajv-keywords/-/ajv-keywords-2.1.1.tgz#617997fc5f60576894c435f940d819e135b80762"

ajv-keywords@^3.0.0:
ajv-keywords@^3.0.0, ajv-keywords@^3.1.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/ajv-keywords/-/ajv-keywords-3.2.0.tgz#e86b819c602cf8821ad637413698f1dec021847a"

Expand All @@ -158,7 +158,7 @@ ajv@^5.0.0, ajv@^5.1.0, ajv@^5.1.5, ajv@^5.2.0, ajv@^5.2.3, ajv@^5.3.0:
fast-json-stable-stringify "^2.0.0"
json-schema-traverse "^0.3.0"

ajv@^6.0.1:
ajv@^6.0.1, ajv@^6.1.0:
version "6.5.1"
resolved "https://registry.yarnpkg.com/ajv/-/ajv-6.5.1.tgz#88ebc1263c7133937d108b80c5572e64e1d9322d"
dependencies:
Expand Down Expand Up @@ -4695,7 +4695,7 @@ loader-utils@^0.2.16:
json5 "^0.5.0"
object-assign "^4.0.1"

loader-utils@^1.0.2, loader-utils@^1.1.0:
loader-utils@^1.0.0, loader-utils@^1.0.2, loader-utils@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/loader-utils/-/loader-utils-1.1.0.tgz#c98aef488bcceda2ffb5e2de646d6a754429f5cd"
dependencies:
Expand Down Expand Up @@ -5085,6 +5085,10 @@ no-case@^2.2.0:
dependencies:
lower-case "^1.1.1"

node-ensure@^0.0.0:
version "0.0.0"
resolved "https://registry.yarnpkg.com/node-ensure/-/node-ensure-0.0.0.tgz#ecae764150de99861ec5c810fd5d096b183932a7"

node-fetch@^1.0.1:
version "1.7.3"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-1.7.3.tgz#980f6f72d85211a5347c6b2bc18c5b84c3eb47ef"
Expand Down Expand Up @@ -5525,6 +5529,13 @@ pbkdf2@^3.0.3:
safe-buffer "^5.0.1"
sha.js "^2.4.8"

pdfjs-dist@2.0.550:
version "2.0.550"
resolved "https://registry.yarnpkg.com/pdfjs-dist/-/pdfjs-dist-2.0.550.tgz#52a5bd05d8b250206ccd2843209cfa3b8f1ea4ae"
dependencies:
node-ensure "^0.0.0"
worker-loader "^2.0.0"

performance-now@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/performance-now/-/performance-now-2.1.0.tgz#6309f4e0e5fa913ec1c69307ae364b4b377c9e7b"
Expand Down Expand Up @@ -6612,6 +6623,13 @@ schema-utils@^0.3.0:
dependencies:
ajv "^5.0.0"

schema-utils@^0.4.0:
version "0.4.5"
resolved "https://registry.yarnpkg.com/schema-utils/-/schema-utils-0.4.5.tgz#21836f0608aac17b78f9e3e24daff14a5ca13a3e"
dependencies:
ajv "^6.1.0"
ajv-keywords "^3.1.0"

select-hose@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/select-hose/-/select-hose-2.0.0.tgz#625d8658f865af43ec962bfc376a37359a4994ca"
Expand Down Expand Up @@ -7730,6 +7748,13 @@ worker-farm@^1.3.1:
dependencies:
errno "~0.1.7"

worker-loader@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/worker-loader/-/worker-loader-2.0.0.tgz#45fda3ef76aca815771a89107399ee4119b430ac"
dependencies:
loader-utils "^1.0.0"
schema-utils "^0.4.0"

wrap-ansi@^2.0.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-2.1.0.tgz#d8fc3d284dd05794fe84973caecdd1cf824fdd85"
Expand Down

0 comments on commit 85b03c6

Please sign in to comment.