Antecedents feed

I was working on a project to convert HTML to PDF, and domPDF/domPDF was used at that time. Next comes the requirement to convert HTML to image. Later, I went to find out that WkHTMLTopdf can generate BOTH PDF and HTML. Immediately overjoyed ground toss up.

Admittedly, WkhtmlTopdf and WkhtmlToImage may not be the best choices, since Google’s Puppeteer is much better. But as a CLI software, it can quickly take us to achieve what we want.

Why not use a third-party package, you might ask. Because the project at work is deployed on Docker, alpine is used for the base image, which may cause unpredictable problems for our subsequent operations. Combined with the potential for multiple projects to use the service together, go is currently used to wrap it as an HTTP service that all projects can access and invoke.

Project address: OverNaive/Html2X

Brief introduction

Html2X is an out-of-the-box HTTP service based on WKhtmltox, which helps the server to generate PDF /image quickly.

Project purpose

  1. The HTTP service replaces the third-party package, which is decoupled from the service system and can be updated independently.
  2. Package the installation of WkHTMLtox in Docker, which can be updated quickly;
  3. Pull the image directly to complete the deployment quickly, truly out of the box.

How to use

Please install Docker by yourself first

1. Obtain the image

  • Local build image:docker build -t overnaive/html2x
  • Remote pull mirror:docker pull overnaive/html2x

2. Run the image

Use docker run –name html2x -p 8080:8888 -it -d overnaive/html2x to run a container.

At this point, an HTTP service is running.

The API documentation

Check out API for Html2X.

The related documents

  • Docker learning Materials: Docker — From Getting Started to Practice
  • Wkhtmltopdf Description document
  • Wkhtmltoimage Description document

Update the plan

Gin is planned to implement complex logic such as parameter verification, authentication and flow limiting.

A free service

If you don’t know about Docker but want to use it quickly; Or maybe you just want to experience it.

Here is a free service that has already been deployed. Check out the free Html2X service.

License

MIT