Skip to content

Latest commit

 

History

History
177 lines (144 loc) · 6.49 KB

README.md

File metadata and controls

177 lines (144 loc) · 6.49 KB

PDF service server side

This is server side of PDF service description.

Index

  1. Overview
  2. Build manually
  3. Or Use Docker Image
  4. API
    1. POST /pdf
    2. POST /image
  5. Debugging
  6. Examples

Overview

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.

  1. url - is site url. Server will generate pdf if you provide this option.
  2. 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 manually

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.

Or Use Docker Image

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

API

This is api reference.

POST /pdf

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',
  });

POST /image

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',
  });

Debugging

To run server in debug mode you should provide DEBUG=true environment variable.

Change Log

This project adheres to Semantic Versioning. Every release is documented on the Github Releases page.

License

Ship is released under the MIT License.

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Contributors

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!