Skip to content
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

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Owner

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.

Copy link
Author

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:

To know the signature directory to create, run ./pdf-sign my_pdf.pdf and see the error message

What would you think about this ?

# 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.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good, but the instruction under ## How also needs correcting.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yes indeed. I'll merge both sections if you are okay


Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For clarity, perhaps add a line such as Thereafter, you can begin using pdf-sign. For example:
Otherwise the below code block could appear like it was about creating signatures.

```
./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.
Expand Down
15 changes: 11 additions & 4 deletions pdf-sign
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Copy link
Owner

Choose a reason for hiding this comment

The 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

  • The user prefers to put the signatures under ~/.config in order not to litter the home directory.
  • ~/.config/pdf_signatures does not exist (yet)
  • $PDF_SIGNATURE_DIR and XDG_CONFIG_HOME are both unset.

In this situation, pdf-sign "" --print-path will print /home/user/.pdf_signatures even though it should have printed /home/user/.config/pdf_signatures.
I'm not exactly sure how to fix this, but I think it's a shame to make this improvement without going all the way.

Copy link
Author

Choose a reason for hiding this comment

The 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")
Expand Down Expand Up @@ -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}')
Expand Down Expand Up @@ -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).
Expand Down Expand Up @@ -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')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps -S and -s are confusingly similar?

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)')
Expand Down