Giter VIP home page Giter VIP logo

html2x's Introduction

HTML2X

HTML2X is a simple yet powerful tool to convert HTML to PNG, JPG, or PDF files. The tool uses Firefox browser in its headless mode to render the HTML and then take a screenshot. The file is converted to the needed format using Imagmagick and is served usig Python Flask; there is also a CLI version to convert files directly from command line as opposed to the API option.

The tool is presented in two easy-to-use docker containers built upon the light weight Alpine Linux distribution.

HTML2X-webservice

Deployment:

Start by pulling the docker image and deploying it locally.

docker pull mwmansour/html2x-webservice
docker run --rm -p 7100:7000 mwmansour/html2x-webservice 

How to use:

Use the tool directly from your browser with this GET request:

http://localhost:7100/?link=https://github.com/
http://localhost:7100/?link=https://github.com/&extension=pdf
http://localhost:7100/?link=https://github.com/&extension=jpg&wh=480,600

As you can see there is only a single required parameter, that is, "link". You can also choose the target extension (available options are pdf, png, and jpg). Moreover, you can change the viewport using the "wh" argument, passing the desired width,height in pixels.

Notice that with the webservice tool you cannot convert local files directly; however, you could use NGINX or any similar service to locally host your files or you could use the CLI tool to convert your local files.

HTML2X-cli

Deployment:

Simply pull the docker image.

docker pull mwmansour/html2x-cli

How to use:

docker run --rm -v $(pwd):/exported/ mwmansour/html2x-cli sh html2x.sh "https://github.com/" 
docker run --rm -v $(pwd):/exported/ mwmansour/html2x-cli sh html2x.sh "https://github.com/" --extension pdf
docker run --rm -v $(pwd):/exported/ mwmansour/html2x-cli sh html2x.sh "https://github.com/" --extension jpg --wh 480,600

Note that you need to surround your links with double quotation marks. You can still specify the extension and viewport size just as in the webservice mode.

To use the CLI service with a local file, prefix its name with "file:///exported/":

docker run --rm -v $(pwd):/exported/ mwmansour/html2x-cli sh html2x.sh file:///exported/index.html

Building the containers

If you prefer to build the containers, you can do so by simply executing the docker_build.sh file after cloning the project.

html2x's People

Contributors

mm-mansour 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.