Run samples quickly ​
Run samples with an HTTP server ​
Foxit PDF SDK for Web includes sample projects for building viewers and demonstrating other features. They live in ./examples inside the SDK package. Start a local web server, open your browser, and go to https://localhost:port or the host IP URL you use. Pick a sample from the directory listing.
To start a server quickly, use the Node.js http-server:
sh
http-serverOpen the browser automatically with -o:
sh
http-server -oOr use Python’s http.server module:
sh
python -m http.server 8000See Set up local server for more options.
Run samples with Snapshot support ​
Features that need a backend—such as Snapshot and collaboration—require npm install and npm start to launch the HTTP server and backend services. Steps:
Before running samples, review package.json in the SDK package:
json
{
"scripts": {
"start": "concurrently --kill-others \"npm run start-http-server\" \"npm run start-snapshot-server\" \"npm run start-collaboration-server\"",
"start-snapshot-server": "node ./server/snapshot/src/index -p 3002",
"start-http-server": "node ./server/index",
"start-collaboration-websocket-server": "node ./server/collaboration-websocket-server/src/index.js -p 9111",
"start-collaboration-server": "node ./server/collaboration-sockjs-server/src/index.js -p 9112"
},
"serve": {
"port": 8080,
"public": "/",
"proxy": {
"target": "http://127.0.0.1:3002",
"changeOrigin": true
}
},
"collaboration-websocket": {
"target": "http://127.0.0.1:9111",
"changeOrigin": true,
"ws": true
},
"collaboration-sockjs": {
"target": "http://127.0.0.1:9112",
"changeOrigin": true,
"ws": true
}
}Check your Node.js and npm versions:
sh
node -v
v10.16.0
npm -v
6.14.1Install dependencies from package.json:
sh
npm installStart services:
sh
npm startOpen http://127.0.0.1:8080 in a browser to browse files and samples.
HTTP server configuration examples ​
This section covers:
- [Start HTTP service with Nginx](#start-http-service-with-nginx/) <br>
- [Start HTTP service with Node.js](#start-http-service-with-nodejs/)
Start HTTP service with Nginx ​
On Windows, assuming Nginx is installed. When Nginx is running, edit nginx.conf under the conf directory. This example configures webViewer directly in nginx.conf:
Download and extract the SDK package.
Open
nginx.confunderNginx/confand add:nginxserver { listen 8080; server_name 127.0.0.1; location / { alias "gotopath/FoxitPDFSDKForWeb/"; charset utf8; index index.html; } }Restart Nginx and open the webViewer in a browser.
Full-featured webViewer:
http://localhost:8080/examples/UIExtension/complete_webViewer/Basic webViewer:
http://localhost:8080/examples/PDFViewCtrl/basic_webViewer/NOTE
The configuration above runs the webViewer, but snapshot will not work until you add the snapshot service. Without it, snapshot images are not cached to the clipboard for paste. Set up the snapshot service as follows:
Install Node.js 9.0 or later (skip if already installed).
In a terminal, go to the
FoxitPDFSDKForWebroot directory.Run
npm installto install dependencies.Run
npm run start-snapshot-serverto start the snapshot service (default port3002).To change the snapshot port, edit the
/server/snapshot/package.jsoninside the SDK package.Add an Nginx reverse proxy in
nginx.conf:nginxserver { listen 8080; server_name 127.0.0.1; location / { alias "gotopath/FoxitPDFSDKForWeb/"; charset utf8; index index.html; } location ~ ^/snapshot/(.+)$ { proxy_pass http://127.0.0.1:3002/snapshot/$1$is_args$args; proxy_redirect off; proxy_request_buffering on; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } }Restart Nginx and refresh the browser—snapshot should work.
Start HTTP service with Node.js ​
With Node.js 9.0 or later installed:
Extract the SDK package. In a terminal, go to the extracted folder and install dependencies:
shnpm installStart the web server:
shnpm startOpen the webViewer in a browser.
Full-featured webViewer:
http://localhost:8080/examples/UIExtension/complete_webViewer/Basic webViewer:
http://localhost:8080/examples/PDFViewCtrl/basic_webViewer/Tip
With
npm start, proxy setup is included and snapshot works without extra Nginx configuration. To change http-server or snapshot ports, editpackage.jsonin the SDK package.Example—change default ports
8080and3002as needed:json{ "serve":{ "port": 8080, "public": "/", "proxy": { "target": "http://127.0.0.1:3002", "changeOrigin": true } } }