previously on
There is a project in the work that needs to convert HTML into PDF. At that time, it was useddompdf/dompdf
。 Later, there is a need to convert HTML into image. Then I went to find itwkhtmltopdf
Both PDF and HTML can be generated. Immediately tossed with joy.
Undeniable?wkhtmltopdf
andwkhtmltoimage
May not be the best choice, after all, Google’sPuppeteer
Much better than it. But as a cli software, it can quickly take us to achieve what we want.
In addition, you may ask why you don’t use third-party packages. Because the project at work is deployed on docker and the basic image is alpine, this may bring unpredictable problems to our subsequent operations. In addition, multiple projects may use this service together in the future, so it is used at presentgo
Wrap it into an HTTP service for all projects to access and call.
Project address:OverNaive/Html2X
, the following is actually a readme document.
Brief introduction
Html2x is an out of the box HTTP service based on wkhtmltox, which helps the server quickly generate PDF / image.
Project purpose
1. Replace the third-party package with HTTP service, which is decoupled from the business system and can be updated independently;
2. Package the installation of wkhtmltox in docker to update the version quickly;
3. You can quickly complete the deployment by directly pulling the image, which is really out of the box.
How to use
Please install docker yourself first
1. Get image
- Build image locally:
docker build -t overnaive/html2x
- Remote pull image:
docker pull overnaive/html2x
2. Run image
Use command:docker run --name html2x -p 8080:8888 -it -d overnaive/html2x
, you can run a container.
At this point, an HTTP service is running.
API documentation
Please go to API for html2x to check.
Related documents
- Docker learning materials: docker — from introduction to practice
- Wkhtmltopdf documentation
- Wkhtmltoimage documentation
Update plan
It is planned to use gin to realize complex logic such as parameter verification, authentication and current limiting.
Free service
If you don’t know about docker, but want to use it quickly; Or you just want to experience it.
Here is a deployed free service. Please check the free html2x service.
License
MIT