Compare commits
2 Commits
c08442f2ea
...
86f77fa1f8
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
86f77fa1f8 | ||
|
|
e678b71778 |
36
install.sh
36
install.sh
@ -1,5 +1,5 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
## INSTALL pdf2zine in Linux or macOS
|
## INSTALL ${REPONAME} in Linux or macOS
|
||||||
### Dependencies:
|
### Dependencies:
|
||||||
# - bash: check with `bash --version`
|
# - bash: check with `bash --version`
|
||||||
# - python3: check with `python3 --version`
|
# - python3: check with `python3 --version`
|
||||||
@ -15,11 +15,11 @@ python3 -m venv --help > /dev/null || echo 'install venv with pip?'
|
|||||||
#
|
#
|
||||||
PREFIX="$HOME/.local"
|
PREFIX="$HOME/.local"
|
||||||
HELP="""
|
HELP="""
|
||||||
$0: install pdf2zine with its virtual environment
|
$0: install ${REPONAME} with its virtual environment
|
||||||
usage:
|
usage:
|
||||||
-h|--help show this help message and exti
|
-h|--help show this help message and exti
|
||||||
-d|--delete remove pdf2zine installation
|
-d|--delete remove ${REPONAME} installation
|
||||||
-f|--force force overwriting of PREFIX/lib/pdf2zine.git
|
-f|--force force overwriting of PREFIX/lib/${REPONAME}.git
|
||||||
can be used for upgrading
|
can be used for upgrading
|
||||||
-p|--prefix PREFIX install into PREFIX/lib and PREFIX/bin
|
-p|--prefix PREFIX install into PREFIX/lib and PREFIX/bin
|
||||||
-v|--verbose print more info (set -x)
|
-v|--verbose print more info (set -x)
|
||||||
@ -33,7 +33,7 @@ while [[ $# -gt 0 ]]; do
|
|||||||
DELETE=1
|
DELETE=1
|
||||||
echo 'THIS DOES NOTHING AT THE MOMENT ...'
|
echo 'THIS DOES NOTHING AT THE MOMENT ...'
|
||||||
echo 'todo:'
|
echo 'todo:'
|
||||||
echo " - [ ] remove $PREFIX/pdf2zine.git"
|
echo " - [ ] remove $PREFIX/${REPONAME}.git"
|
||||||
echo " - [ ] and clean your ~/.bashrc or ~/.zshrc"
|
echo " - [ ] and clean your ~/.bashrc or ~/.zshrc"
|
||||||
exit 0
|
exit 0
|
||||||
;;
|
;;
|
||||||
@ -67,7 +67,7 @@ done
|
|||||||
|
|
||||||
if [[ $PSET != 1 ]]
|
if [[ $PSET != 1 ]]
|
||||||
then
|
then
|
||||||
echo -n """Where to do you want to install 'pdf2zine'?
|
echo -n """Where to do you want to install '${REPONAME}'?
|
||||||
PREFIX [$PREFIX] :
|
PREFIX [$PREFIX] :
|
||||||
"""
|
"""
|
||||||
read userprefix
|
read userprefix
|
||||||
@ -77,21 +77,27 @@ PREFIX [$PREFIX] :
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
REPONAME=pdf2book
|
||||||
|
BINNAME=pdf2zine
|
||||||
LIBDIR=$PREFIX/lib
|
LIBDIR=$PREFIX/lib
|
||||||
BINDIR=$PREFIX/bin
|
BINDIR=$PREFIX/bin
|
||||||
SRCDIR=$LIBDIR/pdf2zine.git
|
SRCDIR=$LIBDIR/${REPONAME}.git
|
||||||
if [[ -d $SRCDIR ]]
|
if [[ -d $SRCDIR ]]
|
||||||
then
|
then
|
||||||
if [[ -z $FORCE ]]
|
if [[ -z $FORCE ]]
|
||||||
then
|
then
|
||||||
echo -n """Directory '$SRCDIR' already exist.
|
echo -n """Directory '$SRCDIR' already exist.
|
||||||
Do you want to overwrite? [y/N] """
|
Do you want to overwrite? [y/N] """
|
||||||
read confirm && [[ $confirm == [yY] || $confirm == [yY][eE][sS] ]] || echo "... exiting ..." && exit 1
|
read confirm
|
||||||
|
if ! [[ $confirm == [yY] || $confirm == [yY][eE][sS] ]]
|
||||||
|
then
|
||||||
|
echo "... exiting ..." && exit 1
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
rm -rf $SRCDIR
|
rm -rf $SRCDIR
|
||||||
fi
|
fi
|
||||||
mkdir -p $LIBDIR $BINDIR
|
mkdir -p $LIBDIR $BINDIR
|
||||||
git clone https://git.wlankabel.at/onipa/pdf2zine.git $SRCDIR
|
git clone https://git.wlankabel.at/onipa/${REPONAME}.git $SRCDIR
|
||||||
python3 -m venv $SRCDIR/.venv
|
python3 -m venv $SRCDIR/.venv
|
||||||
. $SRCDIR/.venv/bin/activate
|
. $SRCDIR/.venv/bin/activate
|
||||||
pip3 install pypdf
|
pip3 install pypdf
|
||||||
@ -99,11 +105,11 @@ echo -n '''#!/bin/bash
|
|||||||
SRCDIR='$SRCDIR'
|
SRCDIR='$SRCDIR'
|
||||||
VENVDIR=$SRCDIR/.venv
|
VENVDIR=$SRCDIR/.venv
|
||||||
. $VENVDIR/bin/activate
|
. $VENVDIR/bin/activate
|
||||||
python3 $SRCDIR/pdf2zine.py $@
|
python3 $SRCDIR/'''${BINNAME}'''.py $@
|
||||||
deactivate
|
deactivate
|
||||||
'''> $BINDIR/pdf2zine
|
'''> $BINDIR/${BINNAME}
|
||||||
chmod +x $BINDIR/pdf2zine
|
chmod +x $BINDIR/${BINNAME}
|
||||||
echo "pdf2zine is installed into '$(realpath $BINDIR)'"
|
echo "$BINNAME} is installed into '$(realpath $BINDIR)'"
|
||||||
#check if $BINDIR is in $PATH
|
#check if $BINDIR is in $PATH
|
||||||
INPATH=$(echo $PATH | tr : '\n' | grep $(realpath $BINDIR) | wc -l )
|
INPATH=$(echo $PATH | tr : '\n' | grep $(realpath $BINDIR) | wc -l )
|
||||||
if [[ $INPATH -lt 1 ]]
|
if [[ $INPATH -lt 1 ]]
|
||||||
@ -120,8 +126,6 @@ then
|
|||||||
if [[ $confirm == [yY] || $confirm == [yY][eE][sS] || -z $confirm ]]
|
if [[ $confirm == [yY] || $confirm == [yY][eE][sS] || -z $confirm ]]
|
||||||
then
|
then
|
||||||
echo 'export PATH=$PATH:'$(realpath $BINDIR) >> $HOME/$RCFILE
|
echo 'export PATH=$PATH:'$(realpath $BINDIR) >> $HOME/$RCFILE
|
||||||
|
echo "you might need to restart your shell"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
#echo inpath: $INPATH
|
|
||||||
echo "you might need to restart your shell"
|
|
||||||
#echo prefix: $PREFIX
|
|
||||||
|
|||||||
69
pdf2zine.py
69
pdf2zine.py
@ -2,26 +2,44 @@
|
|||||||
|
|
||||||
from pypdf import PaperSize, PdfReader, PdfWriter, Transformation
|
from pypdf import PaperSize, PdfReader, PdfWriter, Transformation
|
||||||
from pypdf.generic import RectangleObject
|
from pypdf.generic import RectangleObject
|
||||||
|
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
parser = argparse.ArgumentParser(
|
|
||||||
prog='pdf2zine',
|
|
||||||
description='pdf2zine rearranges pages for signature printing ',
|
|
||||||
epilog='onipa')
|
|
||||||
|
|
||||||
parser.add_argument('pdf_file') # positional argument
|
# TODO
|
||||||
#parser.add_argument('pages', type=int) # positional argument
|
# - default:
|
||||||
#parser.add_argument('-s', '--signature') # option that takes a value
|
# - - folio portrait
|
||||||
parser.add_argument('-v', '--verbose', action='store_true') # on/off flag
|
# - folio fold landscape
|
||||||
parser.add_argument('-z', '--zine', action='store_true', help='Input pdf needs to be 16 pages')
|
# - folio cut landscape
|
||||||
parser.add_argument('-s', '--signature',
|
# - octavo portrait (zine)
|
||||||
dest='signature',
|
# - landscape 0
|
||||||
type=int,
|
# - done:
|
||||||
action='store',
|
|
||||||
default=0,
|
|
||||||
help='')
|
def get_arguments():
|
||||||
args = parser.parse_args()
|
parser = argparse.ArgumentParser(
|
||||||
|
prog='pdf2zine',
|
||||||
|
description='pdf2zine rearranges pages for signature printing ',
|
||||||
|
epilog='onipa')
|
||||||
|
|
||||||
|
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('-z', '--zine', action='store_true', help='Input pdf needs to be 16 pages')
|
||||||
|
parser.add_argument('-s', '--signature',
|
||||||
|
dest='signature',
|
||||||
|
type=int,
|
||||||
|
action='store',
|
||||||
|
default=0,
|
||||||
|
help='')
|
||||||
|
parser.add_argument('-l', '--landscape',
|
||||||
|
dest='landscape',
|
||||||
|
type=int,
|
||||||
|
action='store',
|
||||||
|
default=0,
|
||||||
|
help='')
|
||||||
|
args = parser.parse_args()
|
||||||
|
return args
|
||||||
|
args = get_arguments()
|
||||||
|
|
||||||
signature_size=args.signature
|
signature_size=args.signature
|
||||||
if signature_size < 0 :
|
if signature_size < 0 :
|
||||||
@ -40,9 +58,22 @@ pages=number_of_pages
|
|||||||
lst=[]
|
lst=[]
|
||||||
|
|
||||||
def get_reorder(number_of_pages: int, signature_size: int):
|
def get_reorder(number_of_pages: int, signature_size: int):
|
||||||
|
# TODO:
|
||||||
|
# - if landspace
|
||||||
|
# panu = 64
|
||||||
|
# sisi = 0
|
||||||
|
# 1, 3, 2, 4
|
||||||
|
# 1, 5, 2, 6, 3, 7, 4, 8
|
||||||
|
# 1, 7, 2, 8, 3, 9, 4,10, 5,11, 6, 12
|
||||||
|
# simple cut and combine
|
||||||
|
# 1. i+1
|
||||||
|
# 2. N/2+1
|
||||||
|
# 3. i + 2
|
||||||
|
# 4. N/2+2
|
||||||
panu=number_of_pages
|
panu=number_of_pages
|
||||||
sisi=signature_size
|
sisi=signature_size
|
||||||
|
|
||||||
|
|
||||||
#p\s| 1 | 2 | 3 | 4 |
|
#p\s| 1 | 2 | 3 | 4 |
|
||||||
#-----------------------
|
#-----------------------
|
||||||
# 1 | 4 | 8 | 12 | 16 |
|
# 1 | 4 | 8 | 12 | 16 |
|
||||||
@ -198,6 +229,8 @@ def make_zine(reader, lst):
|
|||||||
# height=PaperSize.A4.width
|
# height=PaperSize.A4.width
|
||||||
# )
|
# )
|
||||||
return writer
|
return writer
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
lst=get_reorder(number_of_pages, signature_size)
|
lst=get_reorder(number_of_pages, signature_size)
|
||||||
if args.zine :
|
if args.zine :
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user