This is server side of PDF service description.
It is the simple HTTP server was written on koa which handle POST request: POST /pdf Body of the request should consist of url or html properties.
- url - is site url. Server will generate pdf if you provide this option.
- html - it is html page code. Server will generate pdf from this page.
Note: If you provide two properties. Server will generate pdf by url.
To prevent wkhtmltopdf installing server should be started from docker container.
Build and start the container. To build the image of the server you in root server directory you should run:
docker build ./
After that the docker image will be built. On the next step you should start the container. For example, to start the image on 3000 port you can run:
docker run -d -p 3000:3000 image_id
Also image exposes only 3000 port, so you should use this port when you map ports.
Image can be loaded from Docker Hub (docker pull paralect/pdf-service). The reference to this image here.
docker pull paralect/pdf-service
docker run -d -p 3000:3000 paralect/pdf-service
Here is the sample of using with docker-compose
version: '2'
services:
pdf-service:
image: paralect/pdf-service
ports:
- "4444:3000"
If you place this code to docker-compose.yml file then you are able to run it by command:
docker-compose up -d
This is api reference.
This request can have a html text and special pdf options (look options sections here)in body. Also this request can have headers which will be used on the page, for examle you can add authorization header (look here) The sample of request to localhost with Fetch API:
fetch('http://localhost:3000/pdf', {
method: 'POST',
body: JSON.stringify({
options,
html,
}),
headers: {
'Content-Type': 'application/json',
},
responseType: 'blob',
});
Or if you want to generate pdf by url.
fetch('http://localhost:3000/pdf', {
method: 'POST',
body: JSON.stringify({
options,
"url": "https://google.com",
}),
headers: {
'Content-Type': 'application/json',
},
responseType: 'blob',
});
This request can have a html text and special image options (look options sections here) The sample of request to localhost with Fetch API:
fetch('http://localhost:3000/pdf', {
method: 'POST',
body: JSON.stringify({
options,
html,
}),
headers: {
'Content-Type': 'application/json',
},
responseType: 'blob',
});
Or if you want to generate pdf by url.
fetch('http://localhost:3000/pdf', {
method: 'POST',
body: JSON.stringify({
options,
"url": "https://google.com",
}),
headers: {
'Content-Type': 'application/json',
},
responseType: 'blob',
});
To run server in debug mode you should provide DEBUG=true environment variable.
This project adheres to Semantic Versioning. Every release is documented on the Github Releases page.
Ship is released under the MIT License.
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.
Thanks goes to these wonderful people (emoji key):
KuhArt 💻 📖 🐛 |
Uladzimir Mitskevich 🤔 🐛 |
NesterenkoNikita 🤔 🐛 |
Andrew Orsich 🤔 🐛 🎨 |
Evgeny Zhivitsa 💻 🎨 |
Женя Филиппович 🐛 |
---|
This project follows the all-contributors specification. Contributions of any kind welcome!