diff --git a/README.md b/README.md index 5b5f9c9..409f95a 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# pdf-unlock # +# pdfunlock # -__pdf_unlock.py__ removes security features from pdfs, to allow unrestricted printing and copying of context. +**pdfunlock** removes security features from pdfs, to allow unrestricted printing and copying of context. ## Installation ## @@ -21,7 +21,8 @@ http://blog.alivate.com.au/poppler-windows Then ``` -pip install tqdm +git clone http://git.wrl.unsw.edu.au:3000/danh/pdfunlock.git +pip install -e pdfunlock ``` @@ -31,14 +32,14 @@ pip install tqdm Search for pdfs inside 'pdf_folder', then create new unlocked versions of the pdfs with the the suffix '-unlocked.pdf': -`> python pdf_unlock.py pdf_folder` +`> pdfunlock pdf_folder` Search for pdfs inside 'pdf_folder', then unlock the pdfs and overwrite the original versions. -`> python pdf_unlock.py pdf_folder -o` +`> pdfunlock pdf_folder -o` Search recursively for pdfs inside 'pdf_folder' and all subfolders, then unlock the pdfs and overwrite the original versions. -`> python pdf_unlock.py pdf_folder -o -r` +`> pdfunlock pdf_folder -o -r` diff --git a/pdfunlock/__init__.py b/pdfunlock/__init__.py new file mode 100644 index 0000000..2199e36 --- /dev/null +++ b/pdfunlock/__init__.py @@ -0,0 +1 @@ +from .pdfunlock import main diff --git a/scripts/pdf_unlock.py b/pdfunlock/pdfunlock.py similarity index 93% rename from scripts/pdf_unlock.py rename to pdfunlock/pdfunlock.py index 707716d..4cda66d 100644 --- a/scripts/pdf_unlock.py +++ b/pdfunlock/pdfunlock.py @@ -6,7 +6,7 @@ including restrictions on: - copying text and images - printing the document -usage: pdf_unlock.py [-h] [-r] [-o] folder +usage: pdf_unlock [-h] [-r] [-o] folder positional arguments: folder name of input folder @@ -21,23 +21,20 @@ Examples: Search for pdfs inside 'pdf_folder', then create new unlocked versions of the pdfs with the the suffix '-unlocked.pdf'. -> python pdf_unlock.py pdf_folder +> pdf_unlock pdf_folder Search for pdfs inside 'pdf_folder', then unlock the pdfs and overwrite the original versions. -> python pdf_unlock.py pdf_folder -o +> pdf_unlock pdf_folder -o Search recursively for pdfs inside 'pdf_folder' and all subfolders, then unlock the pdfs and overwrite the original versions. -> python pdf_unlock.py pdf_folder -o -r +> pdf_unlock pdf_folder -o -r """ -__author__ = "D. Howe" -__version__ = "0.2.0" -__email__ = "d.howe@wrl.unsw.edu.au" - import os +import sys import glob import shutil import argparse @@ -94,7 +91,7 @@ def isencrypted(pdf_name): raise AttributeError('Could not read pdf info.') -def pdf_unlock(pdf_file, overwrite=False): +def pdfunlock(pdf_file, overwrite=False): """Rewrite pdf with Ghostscript, removing encryption. Args: @@ -164,6 +161,12 @@ def main(): '--overwrite', help='overwrite original files', action='store_true') + + # Print usage if no arguments are provided + if len(sys.argv) == 1: + parser.print_help(sys.stderr) + sys.exit(1) + args = parser.parse_args() # Get pdf files diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..a3081ad --- /dev/null +++ b/setup.py @@ -0,0 +1,11 @@ +from setuptools import setup + +setup( + name='pdfunlock', + version='0.3.0', + packages=['pdfunlock'], + install_requires=['tqdm'], + entry_points={'console_scripts':['pdfunlock = pdfunlock:main']}, + author='Dan Howe', + author_email='d.howe@wrl.unsw.edu.au', + description='Remove security features from encrypted pdfs')