A microservice docker container for converting web pages into PDF files.
functional demo: http://skidpdf.vacovsky.us
Get pre-built docker container:
docker run --rm -p 8080:8080 -d vacovsky/skidpdf:latest
curl "http://localhost:8080/pdf?grayscale=false&landscape=true&uri=google.com" > google.pdf
Alternately, browse to http://localhost:8080/pdf?uri=https://github.com/vacoj/skid-pdf&portrait=0&grayscale=0
with chrome to see the PDF.
Streams back to the caller a PDF render of the website passed in the ?uri={someurl}
field.
?uri={google.com,http://google.com,https://google.com}
can be any valid string representing an http endpoint. http/https may be specified.?grayscale={true,false,1,0,T,F}
determines whether or not the PDF will be created in grayscale. Default is full color / grayscale false.?landscape={true,false,1,0,T,F}
determines whether or not the PDF will be created in landscape mode. Default is portrait mode / landscape false.
The POST method on this endpoint allows for more complicated query strings, and soon, headers and other form data to be sent to a target endpoint for PDF generation.
{
"url": "https://requestb.in/17du8md1", // endpoint you want to turn into a PDF
"data": "#safe=off&q=wkhtmltopdf", // should be in query string format: "?key1=somval&key2=anotherVal"
"grayscale": true,
"landscape": true,
"headers": {
"testheader1": "testheader1"
},
"postParams": { // if any values are passed here, the request becomes a POST. If you want a GET, use the "data" field to pass a query string.
"testkey1": "testvalue1",
"testkey2": "testvalue2"
}
}
301s you to the README.md on github.com
Displays the built-in documentation page, where you can test the service using a handy little web tool, as well as see all the documentation for the version you're using.
{
"url": "https://requestb.in/17du8md1", // endpoint you want to turn into a PDF
"data": "#safe=off&q=wkhtmltopdf", // should be in query string format: "?key1=somval&key2=anotherVal"
"grayscale": true,
"landscape": true,
"headers": {
"testheader1": "testheader1"
},
"postParams": { // if any values are passed here, the request becomes a POST. If you want a GET, use the "data" field to pass a query string.
"testkey1": "testvalue1",
"testkey2": "testvalue2"
},
"targetFileName": "test1.pdf", // name of file to be created
"targetFileDest": "./pdfs" // destination folder for file to be placed. Mounting a shared volume seems to be a way to export files for consumption elsewhere. Might add more destination formats later.
}
The above message being posted on the queue will result in a grayscale, landscape oriented PDF file being created at ./pdfs/test1.pdf
, with content rendered from https://google.com.
{
"httpPort": "8080", // must be string; port for http synchronous work
"useQueue": true, // if false, only HTTP synchronous access is turned on
"queueConnectionString": "amqp://username:password@hostname:port/", // AMQP connection string. Tested with RabbitMQ
"queueChannel": "skidpdf", // name of queue to listen on
"autoAck": true // Acknowledge receipt of enqueued messages
}
By default, if no arguments are passed after the binary name, the default settings file provided is used. To specify a settings file, run the binary/container like this:
/path/to/binary /path/to/settings.json
To compile the service and build the docker image, enter the following in your terminal starting in the root of this project (assuming you have docker set up and working):
# build the application
cd src/skid-pdf; go build;
# (optional) install static deps if you want the front end
cd static; bower install --force; cd ..;
# go back to root of the project
cd ../../
# create docker image with all required elements in place
docker build -t skidpdf -f Dockerfile .
# turn the docker image on
docker run -p 8080:8080 -it -d skidpdf
- better support needed for controlling where and how asynchronously generated files are written
- wrap the wkhtmltopdf C library instead of the binary
- open to other suggestions