A sample showing how to load and use PDF.js Express cross origin.
This is useful for situations where you want to load PDF.js Express via CDN.
To run the sample, follow these steps:
- Run
yarn
to install dependencies - Start the fake CDN by running
yarn start:cdn
- In another terminal window, start the client by running
yarn start:client
The client can be accessed at http://localhost:1234
.
Client side code can be found in src/index.js
. You can see in this file that we are loading PDF.js Express assets and our config file from the CDN - which is on another domain.
For sake of this sample, we set up a fake CDN that will run locally on port 3001. The code for the CDN can be found in ./cdn
. It is just a simple Express server that serves static assets.
Static assets are copied from node_modules
into our fake CDN in scripts/copy.js
, which is run when starting the client.
-
scripts/copy.js
The script that prepares and copies our static assets to our CDN. This is executed when runningyarn start:client
-
cdn/files/config.js
This is our config file that we use to call PDF.js Express APIs. -
src/index.js
This is where we tell PDF.js Express to load its static assets from our fake CDN