From 2d82eced449af49a673de2e64e4193753cbcf686 Mon Sep 17 00:00:00 2001 From: "Visco, Paul" Date: Tue, 10 Jan 2017 01:29:36 -0500 Subject: [PATCH] updated instructions --- Readme.md | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- home.html | 40 +++++++++++++++++++++++++++++ 2 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 home.html diff --git a/Readme.md b/Readme.md index 3be04b9..0564ec1 100644 --- a/Readme.md +++ b/Readme.md @@ -1 +1,76 @@ -docker build --rm -t docker-node-pdftk . +webteam/docker-node-pdf-watermarker +======================== + +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. + +# Deployment using copy of project on repos registry where the image is pre-built + +```bash +docker login repos.roswellpark.org:4567 +docker pull repos.roswellpark.org:4567/web-team/docker-node-pdf-watermarker + +docker run -d \ + --name pdf-watermarker \ + --restart=always \ + -p 9021:9021 \ + -e "port=9021" + repos.roswellpark.org:4567/web-team/docker-node-pdf-watermarker +``` + +# Connecting to the container from the host + +``` +docker exec -it pdf-watermarker /bin/bash -c "export TERM=xterm; exec bash" +``` + +# Installing additional commands to debug with apt-get +If you wanted to install nano or telnet from there for debugging +``` +apt-get install telnet +apt-get install nano +``` + +# Using The HTML To PDF Service +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. + +## Example call from CURL in Bash +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. + +```bash +curl -F "watermark=@watermark.pdf" -F "pdf-to-watermark=@my.pdf" http://localhost:9021/watermark > watermarked.pdf +``` + +## Example call from CURL in PHP +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 + 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); +``` + +# Build and Deploy + +If you wanted to build and test this yourself + +```bash +docker build --rm -t yournamespace/docker-node-pdf-watermarker . + +docker run -d \ + --name pdf-watermarker \ + --restart=always \ + -p 9021:9021 \ + yournamespace/docker-node-pdf-watermarker +``` diff --git a/home.html b/home.html new file mode 100644 index 0000000..450003d --- /dev/null +++ b/home.html @@ -0,0 +1,40 @@ + + + + + +

Instructions

+

In order to watermark a pdf, send two PDF files to /watermark, one with fieldname + watermark and one with fieldname pdf-to-watermark. The watermark pdf will get + stamped on each page of the pdf-to-watermark pdf and the resulting PDF + streamed back to the client.

+

CURL Example

+
curl -F "watermark=@watermark.pdf" -F "pdf-to-watermark=@my.pdf" http://localhost:@PORT/watermark > watermarked.pdf
+

PHP Example

+
+<?php
+  $ch = curl_init("http://localhost:@PORT/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);
+
+

Background Info

+

This system is using pdftk as the engine to support this function.

+ +