add first draft of pdf2book.py
This commit is contained in:
parent
dbc6b7b2b3
commit
54fdc697dc
66
README.md
66
README.md
@ -1,7 +1,71 @@
|
|||||||
# README
|
# README
|
||||||
|
|
||||||
## TODO
|
All names are temporary and happy about suggestions of improvement.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## md2verse.sh
|
||||||
|
create `.tex` from markdown files in verse format
|
||||||
|
This bash-script converts an easy markdown file in aqoaba dialect to LaTeX code.
|
||||||
|
This LaTeX code needs a wrapper LaTeX script with
|
||||||
|
```
|
||||||
|
\usepackage{verse, gmverse}
|
||||||
|
```
|
||||||
|
in the preamble and some other features.
|
||||||
|
The path to markdown files, chapter names and other options can be configured in the `conf.sh` file.
|
||||||
|
The `config.sh` file is read by `mkverse.sh`.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## mkverse.sh
|
||||||
|
The `mkverse.sh` script creates a PDF file out of several easy markdown files.
|
||||||
|
Some options need to be set in `config.sh` file.
|
||||||
|
`config.sh` might be renamed to `verse.conf`.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## md2parallel.sh
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## pdf2book.py
|
||||||
|
This script takes a pdf and reorders pages for printing signatures.
|
||||||
|
The number of pages per signature can be varied
|
||||||
|
```
|
||||||
|
s=1: 1,2,3,4 -> 04,01.02,03 i=0
|
||||||
|
08,05.06,07 i=1
|
||||||
|
12,09.10,11 i=2
|
||||||
|
16,13.14,15 i=3
|
||||||
|
20,17.18,19 i=4
|
||||||
|
down=(i+1)*4*s
|
||||||
|
up= (i)*4*s+1
|
||||||
|
#pages_mod=$(python -c " (int(pages/s)+1)*(pages%s) " )
|
||||||
|
for i in $(pages%s)
|
||||||
|
print (down--,up++,up++,down--)
|
||||||
|
|
||||||
|
s=2: 1,2,3,4,5,6,7,8 -> 08,01.02,07 06,03.04,05 i=0
|
||||||
|
16,09.10,15 14,11.12,13 i=1
|
||||||
|
24,17.18,23 22,19.20.21 i=2
|
||||||
|
down=(i+1)*4*s
|
||||||
|
up= (i)*4*s+1
|
||||||
|
for i in range(pages%s):
|
||||||
|
for count in range(2):
|
||||||
|
print (down--,up++,up++,down--)
|
||||||
|
|
||||||
|
s=3: 1,2,3,4,5,6,7,8,9,10,11,12 -> 12,01.02,11 10,03.04,09 08,05.06,07
|
||||||
|
24,13.14,23 22,15.16,21 20,17.18,19
|
||||||
|
s=4: 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16 -> 16,01.02,15 14,03.04,13 12,05.06,11 10,07.08,09
|
||||||
|
32,17,18,31 30,19.20.29 28,21.22.27 26,23.24,25
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### TODO
|
||||||
- [ ] create md2verse.sh
|
- [ ] create md2verse.sh
|
||||||
- [ ] create md2parallel.sh
|
- [ ] create md2parallel.sh
|
||||||
- [ ] create md2tex.sh
|
- [ ] create md2tex.sh
|
||||||
- [ ] create pdf2sig.sh /pdf2book.py -s/--sigsize [0,3,4,5]
|
- [ ] create pdf2sig.sh /pdf2book.py -s/--sigsize [0,3,4,5]
|
||||||
|
- [ ] insert cleaning step (html to md)
|
||||||
|
- [ ] md2html -> sed pertubation -> html2md
|
||||||
|
88
pdf2book.py
Executable file
88
pdf2book.py
Executable file
@ -0,0 +1,88 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
parser = argparse.ArgumentParser(
|
||||||
|
prog='pdf2book',
|
||||||
|
description='pdf2book rearranges pages for signature printing ',
|
||||||
|
epilog='AQOABA')
|
||||||
|
|
||||||
|
#parser.add_argument('pdf-file') # positional argument
|
||||||
|
parser.add_argument('pages', type=int) # positional argument
|
||||||
|
#parser.add_argument('-s', '--signature') # option that takes a value
|
||||||
|
parser.add_argument('-v', '--verbose', action='store_true') # on/off flag
|
||||||
|
parser.add_argument('-s', '--signature',
|
||||||
|
dest='signature',
|
||||||
|
type=int,
|
||||||
|
action='store',
|
||||||
|
default=1,
|
||||||
|
help='')
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
s=args.signature
|
||||||
|
if s < 0 :
|
||||||
|
# print("signature size must be greater than 0!")
|
||||||
|
print("signature size must be positive integer!")
|
||||||
|
exit(1)
|
||||||
|
pages=args.pages
|
||||||
|
#print(pages)
|
||||||
|
|
||||||
|
lst=[]
|
||||||
|
|
||||||
|
def get_reorder(page_number: int, signature_size: int):
|
||||||
|
panu=page_number
|
||||||
|
sisi=signature_size
|
||||||
|
|
||||||
|
# s| 1 | 2 | 3 | 4 |
|
||||||
|
#-----------------------
|
||||||
|
#p | | | |
|
||||||
|
# 1 | 4 | 8 | 12 | 16 |
|
||||||
|
# 2 | 4 | 8 | 12 | 16 |
|
||||||
|
# 3 | 4 | 8 | 12 | 16 |
|
||||||
|
# 4 | 4 | 8 | 12 | 16 |
|
||||||
|
# 5 | 8 | 8 | 12 | 16 |
|
||||||
|
# 6 | 8 | 8 | 12 | 16 |
|
||||||
|
# 7 | 8 | 8 | 12 | 16 |
|
||||||
|
# 8 | 8 | 8 | 12 | 16 |
|
||||||
|
# 9 | 12 | 16 | 12 | 16 |
|
||||||
|
#10 | 12 | 16 | 12 | 16 |
|
||||||
|
#11 | 12 | 16 | 12 | 16 |
|
||||||
|
#12 | 12 | 16 | 12 | 16 |
|
||||||
|
#13 | 16 | 16 | 24 | 16 |
|
||||||
|
|
||||||
|
p=page_number
|
||||||
|
s=signature_size
|
||||||
|
if s == 0:
|
||||||
|
s=1
|
||||||
|
pages_filled= ( int((p-1)/(4*s)) +1 )*4*s
|
||||||
|
s=int(pages_filled/4)
|
||||||
|
pages_filled= ( int((p-1)/(4*s)) +1 )*4*s
|
||||||
|
|
||||||
|
signature_count=int( pages_filled/s/4 )
|
||||||
|
#print(signature_count)
|
||||||
|
for i in range(signature_count):
|
||||||
|
# print("i=",i)
|
||||||
|
down=(i+1)*4*s
|
||||||
|
# print("down=",down)
|
||||||
|
up= (i*4*s)+1
|
||||||
|
# print("up",up)
|
||||||
|
for count in range(s):
|
||||||
|
# print("count=",count)
|
||||||
|
lst.append(down); down -= 1
|
||||||
|
lst.append(up); up += 1
|
||||||
|
lst.append(up); up += 1
|
||||||
|
lst.append(down); down -= 1
|
||||||
|
# print(lst)
|
||||||
|
#print(lst)
|
||||||
|
#print(len(lst))
|
||||||
|
return lst
|
||||||
|
def print_signatures(lst: list,s: int):
|
||||||
|
if s==0: s=1
|
||||||
|
for i in range( len( lst ) ):
|
||||||
|
if ( (i+1) % (4*s) == 0 ):
|
||||||
|
print(lst[i])
|
||||||
|
elif ( (i+1) % (4) == 0 ):
|
||||||
|
print(lst[i], end=' ')
|
||||||
|
else:
|
||||||
|
print(lst[i],end='.')
|
||||||
|
lst=get_reorder(args.pages, args.signature)
|
||||||
|
print_signatures(lst,s)
|
@ -1,4 +1,4 @@
|
|||||||
# Maior é deus
|
# Maior é deus (Titel)
|
||||||
|
|
||||||
Iê!
|
Iê!
|
||||||
|
|
||||||
@ -11,4 +11,4 @@ Grande pequeno sou eu
|
|||||||
|
|
||||||
Camarada ! ...
|
Camarada ! ...
|
||||||
|
|
||||||
## Mestre Pastinha
|
## Mestre Pastinha (Author)
|
||||||
|
Loading…
Reference in New Issue
Block a user