This image is service used to stamp one PDF as a watermark on each page of another and to return the resulting PDF using pdftk.
docker build -t docker-pdf-watermarker .
docker run -d \
--name pdf-watermarker \
--restart=always \
-p 0.0.0.0:9021:9021 \
-e "port=9021" \
docker.io/library/docker-pdf-watermarker
services:
pdf-watermarker:
restart: always
image: docker.io/library/docker-pdf-watermarker
ports:
- "9021:9021"
docker exec -it pdf-watermarker /bin/bash -c "export TERM=xterm; exec bash"
If you wanted to install nano or telnet from there for debugging
apt-get install telnet
apt-get install nano
To convert HTML to PDF you simply pass mutlipart encoded form data to the service.
The system is looking for a key called html and then one file for each corresponding referenced file. e.g. would require a file named logo.png to be uploaded along with the request
E.g. Any src or href that does not start with @FILE: will cause the service to exit for security purposes.
This assumes that the docker image was deployed to localhost on port 9021 and that you are in the test directory of this project where there are two files: one named watermark.pdf and another named my.pdf.
cd test
curl -F "watermark=@watermark.pdf" -F "pdf-to-watermark=@pdf-to-watermark.pdf" http://localhost:9021/watermark > watermarked.pdf
This assumes that the docker image was deployed to localhost on port 9020 and that you are in the test directory of this project where there are two files: one named logo.png and another named styles.css. You can simply run the example.php file in the test directory of this project or use the code below.
<?php
$ch = curl_init("http://localhost:9021/watermark");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, [
'watermark' => new \CurlFile(__DIR__.'/watermark.pdf','application/pdf','watermark.pdf'),
'pdf-to-watermark' => new \CurlFile(__DIR__.'/pdf-to-watermark.pdf','application/pdf','my.pdf')
]);
$result = curl_exec($ch);
file_put_contents("watermarked.pdf", $result);
If you wanted to build and test this yourself
docker build --rm -t paulvisco/docker-node-pdf-watermarker .
docker run -d \
--name pdf-watermarker \
--restart=always \
-p 9021:9021 \
paulvisco/docker-node-pdf-watermarker