Skip to content

Commit

Permalink
Almost ready for a new release
Browse files Browse the repository at this point in the history
  • Loading branch information
nimaid committed Jul 7, 2020
1 parent 8133a6b commit 6f8ea11
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 30 deletions.
Binary file modified Example PDF.pdf
Binary file not shown.
51 changes: 26 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,27 @@ Merges a directory structure of images into a PDF with nested bookmarks.

```
$ bookdir2pdf.py --help
usage: bookdir2pdf.py [-h] -i INPUT_DIR [-o OUTPUT_FILE]
[-s ORDER_NUMBER_SEPERATOR] [-c]
[-s ORDER_NUMBER_SEPARATOR] [-c]
[-p [PURIFY [PURIFY ...]]] [-d DPI] [-t TITLE]
[-a AUTHOR]
Merge nested image direcotry into PDF with nested bookmarks.
Merge nested image directory into PDF with nested bookmarks.
optional arguments:
-h, --help show this help message and exit
-i INPUT_DIR, --input_dir INPUT_DIR
path to nested image directory to merge
-o OUTPUT_FILE, --output_file OUTPUT_FILE
output file path ( defaults to [input_dir].pdf )
-s ORDER_NUMBER_SEPERATOR, --order_number_seperator ORDER_NUMBER_SEPERATOR
the character used to seperate the direcotry ordering
-s ORDER_NUMBER_SEPARATOR, --order_number_separator ORDER_NUMBER_SEPARATOR
the character used to separate the directory ordering
numbers from the bookmark names ( like '.' or ')' )
-c, --table_of_contents
just scan directory and print table of contents
-p [PURIFY [PURIFY ...]], --purify [PURIFY [PURIFY ...]]
purify scanned B&W page ( greyscale, sharpen,
threshold ), named sub-argumets: (sharpen|s)
threshold ), named sub-arguments: (sharpen|s)
(threshold|t)
-d DPI, --dpi DPI dots-per-inch of the input images
-t TITLE, --title TITLE
Expand All @@ -36,7 +35,7 @@ optional arguments:

The PDF here was made using:

`bookdir2pdf.py --input_dir test_dir/ --order_number_seperator . --purify sharpen=1 --title "Example PDF" --dpi 72`
`bookdir2pdf.py --input_dir test_dir/ --order_number_separator . --purify sharpen=1 --title "Example PDF" --dpi 72`

The `.` is what seperates the ordering numbers from the bookmark name in the directory name. For example, the directory name `01. The First Part` has a `.` between the ordering number `01` and the bookmark name `The First Part`.

Expand All @@ -49,22 +48,24 @@ $ bookdir2pdf.py --input_dir test_dir/ --table_of_contents
... [output removed] ...
Example PDF - Table of Contents
-------------------------------
Page #1 Cover Page
Page #2 --- Empty Directory Example
Page #2 --- --- Nested Empty Directory Level 1
Page #2 --- --- --- Nested Empty Directory Level 2
Page #2 --- --- --- --- Nested Empty Directory Level 3
Page #2 Empty Directory .name File Example (allows for forbidden characters like <>?\/*: and also means you can make a really long name like this without hitting the path le
ngth limit of your OS)
Page #2 The First Part
Page #2 --- Chapter 1
Page #4 --- Chapter 2
Page #6 The Middle Part
Page #6 --- Chapter 3
Page #8 --- Chapter 4
Page #10 The Final Part
Page #10 --- Chapter 5
Page #12 --- Chapter 6
test_dir - Table of Contents
----------------------------
Page #1 00. Cover Page
Page #2 --- 01. Empty Directory Example
Page #2 --- --- 01. Nested Empty Directory Level 1
Page #2 --- --- --- 01. Nested Empty Directory Level 2
Page #2 --- --- --- --- 01. Nested Empty Directory Level 3
Page #2 Empty Directory .name File Example (allows for forbidden characters like <>?\/*: and also means you can make a really long name like this without hitting the path length limit of your OS)
Page #2 02. The First Part
Page #2 --- 01. Chapter 1
Page #4 --- 02. Chapter 2
Page #6 03. The Middle Part
Page #6 --- 01. Chapter 3
Page #8 --- 02. Chapter 4
Page #10 04. The Final Part
Page #10 --- 01. Chapter 5
Page #12 --- 02. Chapter 6
Page count: 13
... [output removed] ...
```
13 changes: 8 additions & 5 deletions bookdir2pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ def get_valid_filename(s):
else:
print("PDF author: {}".format(pdf_author))

print("PDF resolution: {} DPI".format(pdf_dpi))
if not args["table_of_contents"]:
print("PDF resolution: {} DPI".format(pdf_dpi))

print("Input directory: {}".format(input_dir))

Expand Down Expand Up @@ -401,6 +402,8 @@ def get_valid_filename(s):

# Update page_list with new images/paths
page_list = new_page_list

print("\tDone purifying images!")

# Make page_list but with only files
page_list_files = [p for p in page_list if os.path.isfile(p)]
Expand All @@ -419,7 +422,6 @@ def get_valid_filename(s):
current_level[part] = OrderedDict()
current_level = current_level[part]

print("\tDone purifying images!")


# Create PDF from page_list(no bookmarks)
Expand Down Expand Up @@ -447,9 +449,10 @@ def get_valid_filename(s):


print()
print("-------- BOOKMARK CREATION --------")
print("Table of Contents will be printed as bookmarks are created.")
print()
if not args["table_of_contents"]:
print("-------- BOOKMARK CREATION --------")
print("Table of Contents will be printed as bookmarks are created.")
print()

# Get ToC title
toc_title = pdf_title
Expand Down

0 comments on commit 6f8ea11

Please sign in to comment.