Git Product home page Git Product logo

mengwoods / sign-pdf-with-transparent-background-signature Goto Github PK

View Code? Open in Web Editor NEW
6.0 1.0 1.0 89.32 MB

Sign PDF. Extract signature from a picture and sign the transparent-background signature to a PDF.

License: MIT License

Python 96.91% Shell 0.02% PowerShell 0.01% Xonsh 0.01% Cython 0.41% C 2.06% C++ 0.44% Fortran 0.13% Forth 0.02%
signature pdf-document-processor pdf-signature

sign-pdf-with-transparent-background-signature's Introduction

sign-pdf-with-transparent-background-signature

Sign PDF file with signature photo input, the tool extracts signature trace and merge it into PDF with specific page, postions and scale values.

Besides it, the repo supports other operations such as PDF's merging, splitting, OCR, watermarking, and make transparent signature picture based on the input photo.

Introduction

The tool takes PDF and signature image inputs and output a signed PDF file.

example result

In the picture above, you could see an example of the input photo and output result, the full signed PDF can be found from files/example-pdf_signed.pdf:

Requirements

  • If you have virtual env installed Virtualenv:

    • In the repository root path, activate virtual python envrionment by source .venv/bin/activate.
  • Or if you prefer to install dependencies yourself:

    • In Python 3.X environment, install by pip install -r requirements.txt in repository root path.

Usage

Put the input files to ./files folder, and python main.py -h to check arguments meaning. Here lists essential arguments for signing PDF:

'-b', '--base-path', default='./files', type=str, help='Base path to the PDF files for processing'
'-t', '--type-of-manipulation', required=True, type=str, \
      choices=['ocr', 'merge', 'split', 'split2image', 'watermark', 'signature', 'make-signature']
'-i', '--input-files', required=True, nargs='+', help="Input PDF files name(s), add space between two files"
'-s', '--signature-file', type=str, help="Sinature picture file name"
'-n', '--signature-page-num', type=int, default=1, help="Signature page number [1, +Inf) of PDF file"
'-o', '--signature-offset-xy', type=parse_two_numbers, default=[0,0], help="Offset proportion of x and y coordinates of the signature. Range is [0,1]"
'-c', '--signature-scale', type=float, default=1, help="Scale (0,+inf) the input sgnature file, set it to negative value if need rotate signature"
'-g', '--gray-threshold', type=float, default=100, help="Gray threshold [0,255] to process signature image"
# The color is only used for signature file generation use.
'--color', type=str, default='black', help='Define the color of output signature'

Sign name to PDF

  • Take a signature photo such as the example.
  • Put the signature photo and PDF file to ./files folder.
  • Select the signature page (-n), gray threshold (-g), scale (-c), and offset proportions (-o), the later two arguments might need try a few times to get best results.
    • Page starts from 1.
    • Gray threshold's range is [0, 255], it is used to extract signature from photo, the default value should be enough for most cases. If not, adjust it and check result.
    • Scale's range is [0, +inf), usually needs to decrease the signature size such as 0.3. Set it to negative value will rotate signature.
    • Offset proportion is in X,Y oder, the top-left corner of the PDF page is the origin, Y is horizontal and X is vertical. Range is [0,1]. See below picture for a reference.

PDFium Library Logo

  • With above, run the program to sign signature. The examples signed PDF uses this command:
    python main.py -t signature -i example-pdf.pdf -s example-signature.jpg -c 0.2 -n 2 -o 0.65,0.72
    
  • One reference command:
    python main.py -t signature -i 1.pdf -s name_photo.jpg -c 0.26 -n 3 -o 0.26,0.6 -g 150

Other supported operations

Here are some other usage examples assuming you have input files in the ./files folder:

  • OCR pdf and save to txt file python main.py -t ocr -i a.pdf
  • Merge mulitple PDFs into one PDF python main.py -t merge -i a.pdf b.pdf
  • Split one PDF to multiple PDFs python main.py -t split -i a.pdf
  • Split one PDF to multiple PNG images python main.py -t split2image -i a.pdf
  • Add watermark to all pages of PDF file python main.py -t watermark -i a.pdf -w watermark.pdf; Add watermark to first (or last) page only python main.py -t watermakr -i a.pdf -w watermark.pdf -p first

To create transparent-background signature in GIF format assuming the input photo is in the ./files folder:

  • Typical operation python main.py -t make-signature -i example-signature.jpg --color blue

TODO

  • Publish Pypi package.
  • Add frontend webpage.
  • Add .venv to the repo
  • After converting, the file size is increased. Find reason and solve it.

sign-pdf-with-transparent-background-signature's People

Contributors

mengwoods avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

tagorepde

sign-pdf-with-transparent-background-signature's Issues

Wrong requeriments.txt

I think you uploaded the wrong version of the requeriments.txt .. for example, i think actionlib is not needed and also gives error.
Regards.

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.