Web service using Grover pdf to generate and manipulate pdfs, png and jpgs.
docker run -p 8080:8080 opinioninet/web-grover
# open localhost:8080 in your browser
Given url or html, will generate a pdf, png or jpg using Grover gem.
Both GET and POST.
Accepted params:
| name | type |
|---|---|
url / html |
Same usage. Will be given to Grover as first param. |
| output_format | pdf / png / jpeg / html : what type of output do you want? |
| grover_options | Will be given to Grover as options for generation. You can also provide any of the supported grover options as any other parameter with prefix grover_<parameter>. |
| filename | Name of the downloaded file without extension |
| content_disposition_location | First part of Content-Disposition header. Default "inline" |
Test it out in your browser:
Or with cURL:
# Basic
curl --request GET \
--url 'localhost:8080/v1/render?url=https%3A%2F%2Fgoogle.com&format=a5' \
-o file.pdf
# 2
curl --request POST \
--url 'http://localhost:8080/v1/render?=' \
--header 'Content-Type: multipart/form-data' \
--header 'User-Agent: insomnia/2023.5.8' \
--form url=https://google.com \
--form 'user_agent=Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0' \
--form grover_wait_until=networkidle2 \
-o file.pdf
For more examples, see doc/insomnia-api-docs.json file. Import it inside Insomnia and play with the docs.
You can provide all the parameters you want to pass to grover if you wrap it inside grover_options object, like so:
# assuming service running on 8080
curl --request POST \
--url 'http://localhost:8080/v1/render?=' \
--header 'Content-Type: application/json' \
--header 'User-Agent: insomnia/2023.5.8' \
--data '{
"url": "https://google.com",
"grover_timeout": 0,
"grover_options": {
"format": "A4",
"margin": {
"top": "5px",
"bottom": "10cm"
},
"user_agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0",
"viewport": {
"width": 640,
"height": 480
},
"prefer_css_page_size": true,
"emulate_media": "screen",
"bypass_csp": true,
"media_features": [
{
"name": "prefers-color-scheme",
"value": "dark"
}
],
"timezone": "Australia/Sydney",
"vision_deficiency": "deuteranopia",
"extra_http_headers": {
"Accept-Language": "en-US"
},
"geolocation": {
"latitude": 59.95,
"longitude": 30.31667
},
"cache": false,
"timeout": 0,
"request_timeout": 1000,
"convert_timeout": 2000,
"launch_args": [
"--font-render-hinting=medium"
],
"wait_until": "domcontentloaded"
}
}'
Having access to the repository of this project you can build it locally.
docker build . -t myapp && docker run -p 8080:8080 myapp
url always wants protocol. so specify either http or https. if you provide url=google.com , you'll get a file with the text google.com.This library only wraps grover ruby gem inside a agoo web server. It does nothing more.
Create all resources inside k8s folder.
By using k8s you may even use an external chrome. In this way you may be able to cale better since you're going to scale only the chrome pod.