-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add --print-path option and README updates #8
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,16 +27,27 @@ Run `pdf-sign -h` or `pdf-create-empty -h` for details. | |
* Install dependencies: `python3.7` or later with module `tkinter`, `gs` (Ghostscript), `pdftk` and `pdfinfo`. | ||
* Copy one or both tools to a directory in your `$PATH`. | ||
|
||
**Installation on Debian** | ||
**Installation and usage on Debian** | ||
|
||
```sh | ||
apt-get update | ||
apt-get install -y coreutils git python3 python3-tk ghostscript pdftk poppler-utils | ||
git clone https://github.com/svenssonaxel/pdf-sign.git | ||
cd pdf-sign | ||
cp pdf-sign pdf-create-empty /usr/local/bin/ | ||
# Get signatures folder | ||
./pdf-sign "" --print-path | ||
# Create this folder | ||
mkdir $(./pdf-sign "" --print-path) | ||
``` | ||
|
||
Now you'll have to put your signature in a PDF file in this folder, you can use `empty-3inx2in.pdf` empty PDF template for example. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good, but the instruction under There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh yes indeed. I'll merge both sections if you are okay |
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For clarity, perhaps add a line such as |
||
``` | ||
./pdf-sign my_document.pdf | ||
``` | ||
|
||
This will generate a second file with `my_document.signed.pdf` in the same directory. | ||
|
||
## Why | ||
|
||
There appears to be a lack of applications that run on Linux and allow for attaching free-hand signatures to PDF files in a good way. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,9 @@ import argparse, os, queue, re, subprocess, sys, tempfile, time | |
|
||
# Inspired by https://unix.stackexchange.com/a/141496 | ||
def main(args): | ||
if args.print_path: | ||
print(getSignatureDir()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will print the correct path in almost all cases. The exception is when
In this situation, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed. But this is out of the scope of this PR, as this is not a problem introduced by this PR, it was already the case before Anyway, I'll finally suggest to turn back and forget adding this option. |
||
sys.exit() | ||
filePath=args.input | ||
if not m("^.*\.(pdf|PDF)$", filePath): | ||
die("Input file must end with .pdf or .PDF") | ||
|
@@ -34,6 +37,7 @@ def main(args): | |
if not args.signature and args.batch: | ||
die('In batch mode, signature must be specified.') | ||
signatureDir=getSignatureDir() | ||
checkSignatureDir(signatureDir) | ||
signatures=[*filter(lambda x: m("^.*\.pdf$", x), os.listdir(signatureDir))] if not args.signature else [None] | ||
if not signatures: | ||
die(f'No .pdf files found in {signatureDir}') | ||
|
@@ -292,12 +296,14 @@ def getSignatureDir(): | |
else: | ||
sd="~/.pdf_signatures" | ||
sd=os.path.expanduser(sd) | ||
if not os.path.exists(sd): | ||
raise Exception(f'Signature directory {sd} does not exist') | ||
if not os.path.isdir(sd): | ||
raise Exception(f'Signature directory {sd} is not a directory') | ||
return sd | ||
|
||
def checkSignatureDir(signatureDir): | ||
if not os.path.exists(signatureDir): | ||
raise Exception(f'Signature directory {signatureDir} does not exist') | ||
if not os.path.isdir(signatureDir): | ||
raise Exception(f'Signature directory {signatureDir} is not a directory') | ||
|
||
# Simple dependency tracking. | ||
# Init with a value or function to calculate the value. | ||
# Update by calling with one argument (as in init). | ||
|
@@ -402,6 +408,7 @@ parser = argparse.ArgumentParser(description='Sign a PDF file.') | |
parser.add_argument('input', metavar='input.pdf', type=str, help='Input PDF file.') | ||
parser.add_argument('-p', '--page', type=int, default=-1, help='The page to sign, negative for counting from the end. (default: -1)') | ||
parser.add_argument('-s', '--signature', type=str, help='Path to file used as signature. Required in batch mode. In GUI mode, the user can choose among files in $PDF_SIGNATURE_DIR, $XDG_CONFIG_HOME/pdf_signatures (defaulting to ~/.config/pdf_signatures), or ~/.pdf_signatures.') | ||
parser.add_argument('-S', '--print-path', help='Print signatures path.', action='store_true') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps |
||
parser.add_argument('-x', '--x-coordinate', type=float, default=0.5, help='Horizontal coordinate of signature center, in page width units. (default: 0.5)') | ||
parser.add_argument('-y', '--y-coordinate', type=float, default=0.75, help='Vertical coordinate of signature center, in page height units. (default: 0.75)') | ||
parser.add_argument('-W', '--width', type=float, default=0.28, help='Width of box to fit signature to, in page width units. (default: 0.28)') | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wish the empty
""
wasn't needed.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wish too, it's quite ugly ! I'm not an argparse expert but I havn't succeed achieving it using argparse.
Anyway, after reconsideration I'd remove this option, as there is an error message that prints the signatures dir if it doesn't exists. In the README we could write something like:
What would you think about this ?