From f46c3bbdd29191654b009c26a28cf99a90484fec Mon Sep 17 00:00:00 2001 From: Elena ``of Valhalla'' Grandi Date: Sat, 12 Aug 2023 10:22:29 +0200 Subject: Moved page manipulation scripts into a subdirectory --- a5_book.py | 71 ------------------------------ a6_book.man.rst | 62 --------------------------- a6_book.py | 90 --------------------------------------- page_manipulation/a5_book.py | 71 ++++++++++++++++++++++++++++++ page_manipulation/a6_book.man.rst | 62 +++++++++++++++++++++++++++ page_manipulation/a6_book.py | 90 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 223 insertions(+), 223 deletions(-) delete mode 100755 a5_book.py delete mode 100644 a6_book.man.rst delete mode 100755 a6_book.py create mode 100755 page_manipulation/a5_book.py create mode 100644 page_manipulation/a6_book.man.rst create mode 100755 page_manipulation/a6_book.py diff --git a/a5_book.py b/a5_book.py deleted file mode 100755 index 846ca86..0000000 --- a/a5_book.py +++ /dev/null @@ -1,71 +0,0 @@ -#!/usr/bin/env python3 - -import argparse -import os.path -import subprocess - - -SIGNATURE = ( - 15, 0, - 1, 14, - 13, 2, - 3, 12, - 11, 4, - 5, 10, - 9, 6, - 7, 8 -) - - -def get_parser(): - parser = argparse.ArgumentParser() - parser.add_argument( - "--file", '-f', - help="Name of the PDF file", - ) - parser.add_argument( - "pagespec", - help="Page selection. At the moment only '-' is supported" - ) - return parser - - -def main(): - parser = get_parser() - args = parser.parse_args() - pspec = args.pagespec.split('-') - try: - start = int(pspec[0]) - end = int(pspec[1]) - except ValueError: - parser.print_usage() - except IndexError: - parser.print_usage() - - pages = [str(i) for i in range(start, end+1)] - if len(pages) % 16 != 0: - empty = 16 - len(pages) % 16 - pages = pages + ["{}"] * empty - - rearranged = [] - while pages: - for i in SIGNATURE: - rearranged.append(pages[i]) - pages = pages[16:] - - base, ext = os.path.splitext(args.file) - out_fname = base + '-book' + ext - - subprocess.run([ - 'pdfjam', - '--nup', '2x1', - "--landscape", - #'--no-tidy', - '-o', out_fname, - args.file, - ','.join(rearranged) - ]) - - -if __name__ == "__main__": - main() diff --git a/a6_book.man.rst b/a6_book.man.rst deleted file mode 100644 index ca371cc..0000000 --- a/a6_book.man.rst +++ /dev/null @@ -1,62 +0,0 @@ -============ - a6_book.py -============ - ----------------------------------------------------------------- - Arrange pdf pages to print an a6 book with 16-pages signatures ----------------------------------------------------------------- - -:Authors: Elena “of Valhalla” Grandi -:Date: 2021-10-19 -:Copyright: 2021 Elena Grandi -:Version: 0.20211019 -:Manual Section: 1 - -SYNOPSIS --------- - - a6_book.py [-h] --file FILE pagespec - -DESCRIPTION ------------ - -OPTIONS -------- - -pagespec - Page selection. At the moment only '-' is supported - --h, --help - Show this help message and exit ---file FILE, -f FILE - Name of the PDF file - -LICENSE -------- - -Copyright (c) 2021, Elena Grandi -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -* Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. -* Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. -* Neither the name of the nor the - names of its contributors may be used to endorse or promote products - derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY -DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - diff --git a/a6_book.py b/a6_book.py deleted file mode 100755 index 059a717..0000000 --- a/a6_book.py +++ /dev/null @@ -1,90 +0,0 @@ -#!/usr/bin/env python3 - -import argparse -import os.path -import subprocess - - -SIGNATURE = ( - 15, 0, 13, 2, - 1, 14, 3, 12, - 11, 4, 9, 6, - 5, 10, 7, 8, -) - -SIGNATURE_32 = ( - 15, 0, 31, 16, - 1, 14, 17, 30, - 13, 2, 29, 18, - 3, 12, 19, 28, - 11, 4, 27, 20, - 5, 10, 21, 26, - 9, 6, 25, 22, - 7, 8, 23, 24, -) - - -def get_parser(): - parser = argparse.ArgumentParser() - parser.add_argument( - "--file", '-f', - help="Name of the PDF file", - ) - parser.add_argument( - "--double", "-d", - action="store_true", - help="Put two signatures on 4 A4 sheet. Pages should be a " - "multiple of 32", - ) - parser.add_argument( - "pagespec", - help="Page selection. At the moment only '-' is supported" - ) - return parser - - -def main(): - parser = get_parser() - args = parser.parse_args() - pspec = args.pagespec.split('-') - try: - start = int(pspec[0]) - end = int(pspec[1]) - except ValueError: - parser.print_usage() - except IndexError: - parser.print_usage() - - if args.double: - signature = SIGNATURE_32 - else: - signature = SIGNATURE - sig_len = len(signature) - - pages = [str(i) for i in range(start, end+1)] - if len(pages) % sig_len != 0: - empty = sig_len - len(pages) % sig_len - pages = pages + ["{}"] * empty - - rearranged = [] - - while pages: - for i in signature: - rearranged.append(pages[i]) - pages = pages[sig_len:] - - base, ext = os.path.splitext(args.file) - out_fname = base + '-book' + ext - - subprocess.run([ - 'pdfjam', - '--nup', '2x2', - #'--no-tidy', - '-o', out_fname, - args.file, - ','.join(rearranged) - ]) - - -if __name__ == "__main__": - main() diff --git a/page_manipulation/a5_book.py b/page_manipulation/a5_book.py new file mode 100755 index 0000000..846ca86 --- /dev/null +++ b/page_manipulation/a5_book.py @@ -0,0 +1,71 @@ +#!/usr/bin/env python3 + +import argparse +import os.path +import subprocess + + +SIGNATURE = ( + 15, 0, + 1, 14, + 13, 2, + 3, 12, + 11, 4, + 5, 10, + 9, 6, + 7, 8 +) + + +def get_parser(): + parser = argparse.ArgumentParser() + parser.add_argument( + "--file", '-f', + help="Name of the PDF file", + ) + parser.add_argument( + "pagespec", + help="Page selection. At the moment only '-' is supported" + ) + return parser + + +def main(): + parser = get_parser() + args = parser.parse_args() + pspec = args.pagespec.split('-') + try: + start = int(pspec[0]) + end = int(pspec[1]) + except ValueError: + parser.print_usage() + except IndexError: + parser.print_usage() + + pages = [str(i) for i in range(start, end+1)] + if len(pages) % 16 != 0: + empty = 16 - len(pages) % 16 + pages = pages + ["{}"] * empty + + rearranged = [] + while pages: + for i in SIGNATURE: + rearranged.append(pages[i]) + pages = pages[16:] + + base, ext = os.path.splitext(args.file) + out_fname = base + '-book' + ext + + subprocess.run([ + 'pdfjam', + '--nup', '2x1', + "--landscape", + #'--no-tidy', + '-o', out_fname, + args.file, + ','.join(rearranged) + ]) + + +if __name__ == "__main__": + main() diff --git a/page_manipulation/a6_book.man.rst b/page_manipulation/a6_book.man.rst new file mode 100644 index 0000000..ca371cc --- /dev/null +++ b/page_manipulation/a6_book.man.rst @@ -0,0 +1,62 @@ +============ + a6_book.py +============ + +---------------------------------------------------------------- + Arrange pdf pages to print an a6 book with 16-pages signatures +---------------------------------------------------------------- + +:Authors: Elena “of Valhalla” Grandi +:Date: 2021-10-19 +:Copyright: 2021 Elena Grandi +:Version: 0.20211019 +:Manual Section: 1 + +SYNOPSIS +-------- + + a6_book.py [-h] --file FILE pagespec + +DESCRIPTION +----------- + +OPTIONS +------- + +pagespec + Page selection. At the moment only '-' is supported + +-h, --help + Show this help message and exit +--file FILE, -f FILE + Name of the PDF file + +LICENSE +------- + +Copyright (c) 2021, Elena Grandi +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. +* Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. +* Neither the name of the nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + diff --git a/page_manipulation/a6_book.py b/page_manipulation/a6_book.py new file mode 100755 index 0000000..059a717 --- /dev/null +++ b/page_manipulation/a6_book.py @@ -0,0 +1,90 @@ +#!/usr/bin/env python3 + +import argparse +import os.path +import subprocess + + +SIGNATURE = ( + 15, 0, 13, 2, + 1, 14, 3, 12, + 11, 4, 9, 6, + 5, 10, 7, 8, +) + +SIGNATURE_32 = ( + 15, 0, 31, 16, + 1, 14, 17, 30, + 13, 2, 29, 18, + 3, 12, 19, 28, + 11, 4, 27, 20, + 5, 10, 21, 26, + 9, 6, 25, 22, + 7, 8, 23, 24, +) + + +def get_parser(): + parser = argparse.ArgumentParser() + parser.add_argument( + "--file", '-f', + help="Name of the PDF file", + ) + parser.add_argument( + "--double", "-d", + action="store_true", + help="Put two signatures on 4 A4 sheet. Pages should be a " + "multiple of 32", + ) + parser.add_argument( + "pagespec", + help="Page selection. At the moment only '-' is supported" + ) + return parser + + +def main(): + parser = get_parser() + args = parser.parse_args() + pspec = args.pagespec.split('-') + try: + start = int(pspec[0]) + end = int(pspec[1]) + except ValueError: + parser.print_usage() + except IndexError: + parser.print_usage() + + if args.double: + signature = SIGNATURE_32 + else: + signature = SIGNATURE + sig_len = len(signature) + + pages = [str(i) for i in range(start, end+1)] + if len(pages) % sig_len != 0: + empty = sig_len - len(pages) % sig_len + pages = pages + ["{}"] * empty + + rearranged = [] + + while pages: + for i in signature: + rearranged.append(pages[i]) + pages = pages[sig_len:] + + base, ext = os.path.splitext(args.file) + out_fname = base + '-book' + ext + + subprocess.run([ + 'pdfjam', + '--nup', '2x2', + #'--no-tidy', + '-o', out_fname, + args.file, + ','.join(rearranged) + ]) + + +if __name__ == "__main__": + main() -- cgit v1.2.3