2015-12-22 04:46:50 +09:00
|
|
|
## Overview
|
|
|
|
|
2016-04-07 01:36:41 +09:00
|
|
|
Example to demonstrate PDF.js library usage with Webpack.
|
2015-12-22 04:46:50 +09:00
|
|
|
|
|
|
|
## Getting started
|
|
|
|
|
2018-05-20 22:18:43 +09:00
|
|
|
Install the example dependencies and build the project:
|
2015-12-22 04:46:50 +09:00
|
|
|
|
2017-05-11 08:28:18 +09:00
|
|
|
$ gulp dist-install
|
2016-04-07 01:36:41 +09:00
|
|
|
$ cd examples/webpack
|
|
|
|
$ npm install
|
2018-05-20 22:18:43 +09:00
|
|
|
$ ./node_modules/webpack/bin/webpack.js
|
2015-12-22 04:46:50 +09:00
|
|
|
|
2018-05-20 22:18:43 +09:00
|
|
|
You can observe the build results by running `gulp server` and navigating to
|
|
|
|
http://localhost:8888/examples/webpack/index.html.
|
2015-12-22 04:46:50 +09:00
|
|
|
|
2018-05-20 22:18:43 +09:00
|
|
|
Refer to the `main.js` and `webpack.config.js` files for the source code.
|
|
|
|
Note that PDF.js packaging requires packaging of the main application and
|
|
|
|
the worker code, and the `workerSrc` path shall be set to the latter file.
|
2019-08-20 04:36:06 +09:00
|
|
|
|
2021-04-26 00:18:06 +09:00
|
|
|
### Minification
|
|
|
|
|
|
|
|
If you are configuring Webpack to output a minified build, please note that you
|
|
|
|
*must* configure the minifier to keep original class/function names intact;
|
|
|
|
otherwise the build is not guaranteed to work correctly.
|
|
|
|
|
2019-08-20 04:36:06 +09:00
|
|
|
## Worker loading
|
|
|
|
|
2020-06-04 03:50:41 +09:00
|
|
|
If you are getting the `Setting up fake worker` warning, make sure you are
|
|
|
|
importing `pdfjs-dist/webpack` which is the zero-configuration method for
|
|
|
|
Webpack users. You will need to install
|
2021-01-07 22:15:47 +09:00
|
|
|
[worker-loader](https://github.com/webpack-contrib/worker-loader) (version 3.0.0 or higher is required), as a
|
2020-06-04 03:50:41 +09:00
|
|
|
dependency in your project in order to use `pdfjs-dist/webpack` (configuring
|
|
|
|
`worker-loader` is not necessary; just installing it is sufficient).
|
2019-08-20 04:36:06 +09:00
|
|
|
|
2021-05-29 09:46:56 +09:00
|
|
|
import * as pdfjsLib from 'pdfjs-dist/webpack';
|
2019-08-20 04:36:06 +09:00
|
|
|
|
|
|
|
For a full working example refer to [this repository](https://github.com/yurydelendik/pdfjs-react).
|