Giter Site home page Giter Site logo

meteyou / docker-pdf-watermarker Goto Github PK

View Code? Open in Web Editor NEW

This project forked from surebert/docker-pdf-watermarker

0.0 0.0 0.0 241 KB

Creates http service node js and pdftk to watermark one PDF over another on each page

License: MIT License

Shell 2.12% JavaScript 63.94% PHP 7.98% HTML 21.22% Dockerfile 4.73%

docker-pdf-watermarker's Introduction

Docker HTTP 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.

Build and Deploy

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

Docker-compose

services:
  pdf-watermarker:
  restart: always
  image: docker.io/library/docker-pdf-watermarker
  ports:
    - "9021:9021"

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.

cd test
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
  $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

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

docker-pdf-watermarker's People

Contributors

pvrpccc avatar meteyou avatar surebert avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.