This is a proxy server to use with HTML sample by PDFTron
This project is experimental. A proxy server is used to serve webpage assets. This is done to get around various security issues, when loading a webpage in an iframe. This works for a good amount of pages but there are many exceptions. If you have a subset of web pages that you would like to support then we recommend forking this repository and making the necessary fixes. We won't be making those changes because it would likely result in other pages failing.
npm install @pdftron/webviewer-html-proxy-server
Call the createServer
function in your server component and pass in an object that includes SERVER_ROOT
and PORT
. You can, optionally, pass in CORS_OPTIONS
- an object to configure CORS, COOKIE_SETTING
- an object to configure COOKIE and ALLOW_HTTP_PROXY
, a boolean value to allow loading localhost files and for unsecured HTTP websites to be proxied.
See: https://expressjs.com/en/resources/middleware/cors.html and https://expressjs.com/en/api.html#res.cookie
const HTMLProxyServer = require('@pdftron/webviewer-html-proxy-server');
HTMLProxyServer.createServer({
SERVER_ROOT: `http://localhost`,
PORT: 3100
});
Setting CORS_OPTIONS
example:
HTMLProxyServer.createServer({
SERVER_ROOT: `http://localhost`,
PORT: 3100,
CORS_OPTIONS: {
"origin": "*",
"methods": "GET,HEAD,PUT,PATCH,POST,DELETE",
"preflightContinue": false,
"optionsSuccessStatus": 204
}
});
Setting COOKIE_SETTING
example:
HTMLProxyServer.createServer({
SERVER_ROOT: `http://localhost`,
PORT: 3100,
COOKIE_SETTING: {
sameSite: 'none',
secure: true
}
});
Setting ALLOW_HTTP_PROXY
example:
HTMLProxyServer.createServer({
SERVER_ROOT: `http://localhost`,
PORT: 3100,
ALLOW_HTTP_PROXY: true
});
URL : /pdftron-proxy?url=
Query Parameters : url=[string]
where url
is a publicly accessible link.
Method : GET
Condition : If the URL can be successfuly proxied
Code : 200 OK
Content example
{
"validUrl": "https://www.pdftron.com/"
}
Condition : If URL can not be proxied.
Code : 400
Content : { errorMessage: 'Please enter a valid URL and try again.' }
URL : /pdftron-download?url=
Query Parameters : url=[string]
where url
is a publicly accessible link.
Method : GET
Condition : If URL can be loaded in puppeteer.
Code : 200 OK
Content example
{
"buffer": "<some image buffer>",
"pageDimensions": { "width": 1440, "height": 770 }
}
Condition : If URL can not be loaded in puppeteer.
Code : 400
Content : { errorMessage: 'Error taking screenshot from puppeteer' }