-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
116 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. <img src="@FILE:logo.png"> 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 "[email protected]" -F "[email protected]" 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 | ||
<?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); | ||
``` | ||
|
||
# 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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<html> | ||
<head> | ||
<style type="text/css"> | ||
body{ | ||
background-color:orange; | ||
color:brown; | ||
} | ||
pre { | ||
background-color:#DFDFDF; | ||
color:#666; | ||
padding:30px; | ||
marging:10px; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<h1>Instructions</h1> | ||
<p>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.</p> | ||
<h2>CURL Example</h2> | ||
<pre>curl -F "[email protected]" -F "[email protected]" http://localhost:@PORT/watermark > watermarked.pdf</pre> | ||
<h2>PHP Example</h2> | ||
<pre> | ||
<?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); | ||
</pre> | ||
<h1>Background Info</h1> | ||
<p>This system is using pdftk as the engine to support this function.</p> | ||
</body> | ||
</html> |