Git Product home page Git Product logo

electron-render-service's Introduction

electron-render-service

Greenkeeper badge Build Status Docker Hub npm

Simple PDF/PNG/JPEG render service, accepts webpage URL and returns the resource.

Alternatively an HTML payload can be POST-ed.

Docker usage

Based on official Debian Jessie image, uses latest electron.

  1. docker run -t -e RENDERER_ACCESS_KEY=secret -p 3000:3000 msokk/electron-render-service
  2. wget -O out.pdf 'http://<node_address>:3000/pdf?accessKey=secret&url=https%3A%2F%2Fgithub.com%2Fmsokk%2Felectron-render-service'

NB: Set bigger shared memory size --shm-size=Xm (default: 64m) if dealing with very heavy pages.

Docker Swarm needs extra configuration to work - --shm-size is not implemented use --mount type=tmpfs,dst=/dev/shm,tmpfs-size=134217728 instead and blank hostname -e HOSTNAME=.

Installation on Debian with Node.js

# Enable contrib packages
sed -i 's/main/main contrib/g' /etc/apt/sources.list

# Install packages needed for runtime
apt-get update && apt-get install -y xvfb libgtk2.0-0 ttf-mscorefonts-installer libnotify4 libgconf2-4 libxss1 libnss3 dbus-x11

# Install from NPM
npm install -g electron-render-service

# Run in virtual framebuffer
RENDERER_ACCESS_KEY=secret xvfb-run --server-args="-screen 0 1024x768x24" electron-render-service

wget -O out.pdf 'http://localhost:3000/pdf?accessKey=secret&url=https%3A%2F%2Fgithub.com%2Fmsokk%2Felectron-render-service'

Endpoints

GET /pdf - Render PDF

Query params (About PDF params):

  • accessKey - Authentication key.
  • url - Full URL to fetch.
  • pageSize - Specify page size of the generated PDF. Can be A3, A4, A5, Legal, Letter, Tabloid or <width>x<height> in microns (e.g. 210000x297000 for A4)(default: A4)
  • marginsType - Specify the type of margins to use (default: 0)
  • printBackground - Whether to print CSS backgrounds. (default: true)
  • landscape - true for landscape, false for portrait. (default: false)
  • removePrintMedia - Removes any <link media="print"> stylesheets on page before render. (default: false)
  • delay - Specify how many seconds to wait before generating the PDF (default: 0)
  • waitForText - Specify a specific string of text to find before generating the PDF (default: false)

POST /pdf

Identical as above, omit url and provide HTML in request body.

GET /png|jpeg - Render PNG/JPEG

Query params:

  • accessKey - Authentication key.
  • url - Full URL to fetch.
  • quality - JPEG quality. (default: 80)
  • delay - Specify how many seconds to wait before generating the image (default: 0)
  • waitForText - Specify a specific string of text to find before generating the image (default: false)
  • browserWidth - Browser window width (default: rect.width || env.WINDOW_WIDTH, max: 3000)
  • browserHeight - Browser window height (default: rect.height || env.WINDOW_HEIGHT, max: 3000)
  • Clipping rectangle (optional, but all four fields must be defined)
    • clippingRect[x]
    • clippingRect[y]
    • clippingRect[width]
    • clippingRect[height]

POST /png|jpeg

Identical as above, omit url and provide HTML in request body.

GET /stats - Display render pool stats

Query params:

  • accessKey - Generic authentication key is required.

Environment variables

Required
  • RENDERER_ACCESS_KEY or RENDERER_ACCESS_KEY_<suffix> - Secret key for limiting access. Suffixed keys are used as labels in access log for debugging usage.
Optional
  • CONCURRENCY - Number of browser windows to run in parallel (default: 1)
  • TIMEOUT - Number of seconds before request timeouts (default: 30)
  • WINDOW_WIDTH - Default window width (default: 1024)
  • WINDOW_HEIGHT - Default window height (default: 768)
  • HOSTNAME - Hostname to accept Express connections on (default: 0.0.0.0)
  • PORT - (default: 3000)

Delayed Rendering

Not all content is loaded once the DOM is loaded, some data can take time because calls are being made via websockets and other methods. You can delay the rendering by either providing a delay value in the query string or you can provide waitForText in the query string.

If you specify waitForText the service will continually scan the loaded URL until the overall timeout is reached. If the text passed to the variable waitForText is found before the timeout, the PDF/image will generate and return.

electron-render-service's People

Contributors

ekristen avatar greenkeeper[bot] avatar mcuelenaere avatar msokk avatar pcornelissen avatar reggino avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.