pystitcher stitches your PDF files together, generating nice customizable bookmarks for you using a declarative markdown file as input

Overview

pystitcher

pystitcher stitches your PDF files together, generating nice customizable bookmarks for you using a declarative input in the form of a markdown file. It is written in pure python and uses PyPDF3 for reading and writing PDF files.

Description

pystitcher is a command line tool, with very few cli options:

usage: pystitcher [-h] [--version] [-v] [--cleanup | --no-cleanup] spine.md output.pdf

Stitch PDF files together

positional arguments:
  spine.md              Input markdown file
  output.pdf            Output PDF file

optional arguments:
  -h, --help            show this help message and exit
  --version             show program's version number and exit
  -v, --verbose         log more things
  --cleanup, --no-cleanup
                        Delete temporary files (default: True)

Given this input:

existing_bookmarks: remove
title: Complete Guide to the Personal Data Protection Bill
author: Medianama
keywords: privacy, surveillance, personal data protection
subject: Personal Data Protection Bill
# A Complete Guide to the Personal Data Protection Bill

- [Cover](cover.pdf)

# The Bills

- [Personal Data Protection Bill, 2019](https://example.com/2019-bill.pdf)
- [Personal Data Protection Bill, 2018](https://example.com/2018-bill.pdf)

# Other key reading material

- [Srikrishna Committee Report](2.a.pdf)
- [Dvara Research's Personal Data Protection Bill](2.b.pdf)
- [MP Shashi Tharoor's Data Protection Bill](2.c.pdf)
- [MP Jay Panda's Data Protection Bill](2.d.pdf)
- [SaveOurPrivacy.in bill](2.e.pdf)
- [TRAI recommendations on privacy](2.f1.pdf)
- [Comments on TRAI recommendations on privacy](2.f2.pdf)

Will generate a PDF with proper bookmarks:

https://i.imgur.com/qPVpZGt.png

And the correct metadata:

Title:          Complete Guide to the Personal Data Protection Bill
Subject:        Personal Data Protection Bill
Keywords:       privacy, surveillance, personal data protection
Author:         Medianama
Creator:        pystitcher/1.0.0
Producer:       pystitcher/1.0.0

Configuration options can be specified with Meta data at the top of the file.

Option Notes
fit Default fit of the bookmark. Can be overwritten per bookmark See wiki for more details.
author PDF Author
keywords PDF Keywords
subject PDF Subject
title PDF Title. If left unspecified, first Heading (h1) in the document is used.
existing_bookmarks What to do with existing bookmarks in individual files. Options are keep, flatten, and remove. See docs for more details.

Additionally, PDF links specified in markdown can have attributes to alter the PDFs before merging. The below attribute will rotate the second PDF file by 90 degrees clockwise before merging:

[Part 1](1.pdf)
[Part 2](2.pdf){: rotate="90"}

And the below attribute will merge only pages 2 to 5, both inclusive, from the second PDF file:

[Part 1](1.pdf)
[Part 2](2.pdf){: start=2 end=5}

The list of available attributes are:

Attribute Notes
rotate Rotate the PDF. Valid values are 90, 180, 270
start Start page number for PDF page selection
end End page number for PDF page selection

Documentation

Additional documentation is maintained on the project wiki on GitHub.

Comments
  • Installation instructions: please update the readme front page

    Installation instructions: please update the readme front page

    Thanks for your work providing this tool. I ended up here looking for an alternative to python stapler.

    There's a lot of good and important stuff on the README.

    Please add one or two lines, at the top of the README with the most important stuff. How to install it.

    It might be obvious to you, a python developer, but not for a potential end user. Is it using "pip install xyz" ? Will it work with pipx ? Are there any "official" packages for Linux distro xyz ?

    Thanks in advance.

    opened by m040601 5
  • Added PDF rotation filter

    Added PDF rotation filter

    Closes #1

    Added a test input in book-rotate.md as well.

    I've been using pdftk a lot recently, but pystitcher definitely works better for me. Thanks for working on it!

    opened by Vonter 3
  • Python 3.9 required?

    Python 3.9 required?

    Thanks for the great code, it worked well for me putting books back together from chapters in Elsevier. The only issue I had was that it required using Python 3.9 at a minimum. I initially had an error under Python 3.7, complaining about line 56 of skeleton.py with reference to argparse.BooleanOptionalAction ; I lost the actual error message e.g see here for related.

    bug 
    opened by jd-foster 2
  • Add Tests

    Add Tests

    Starting Integration tests. Currently tracks:

    • [x] Sticher functionality by generating all test files
    • [x] Number of pages in these test files
    • [x] Bookmarks (title/destination page number)
    • [x] Bookmark level
    • [x] PDF metadata
    • [x] Attributes: Rotation
    • [x] Attributes: Page Selection
    • [x] Run CI tests on GitHub Actions
    • [x] Generate coverage reports

    Missing testcases:

    • [ ] Remote fetching (Will take this up later)
    • [x] Custom Title
    • [x] H2/H3 as bookmarks
    • [x] Disable cleanup and validate
    enhancement 
    opened by captn3m0 1
  • Specify Zoom level for links in markdown

    Specify Zoom level for links in markdown

    [Personal Data Protection Bill, 2019](1.a.pdf){: zoom=FitWidth}
    

    Other options:

        Inherit - Inherit zoom
        FitPage - Fit page width+height
        FitWidth - Fit page width
        FitHeight - Fit page height
        ##% - Zoom to ##% eg 50% = 50% zoom
    
    opened by captn3m0 0
  • Support external URLs to fetch PDF

    Support external URLs to fetch PDF

    # Title
    
    - [chapter 1](https://example.com/chapter1.pdf)
    - [chapter 2](https://example.com/chapter2.pdf)
    

    Download the PDFs, cache them and merge accordingly.

    opened by captn3m0 0
  • Auto Page numbering support

    Auto Page numbering support

    Want to be able to add page numbers to the generated PDF with font configuration. Use case - Printouts. Once this is done, easy to add a Table of Contents too. #6

    I was exploring and found this as one option: https://github.com/vlad-anisov/numbering2pdf/blob/main/numbering2pdf/numbering2pdf.py It uses reportlab to generate empty numbered PDFs and merges those pages with the existing pages one by one.

    Happy to work on this issue, if you suggest a preferred method (given your research) to implement this.

    enhancement 
    opened by lprsd 1
  • Fix current working directory hack

    Fix current working directory hack

    Currently, we switch our CWD to the markdown file directory, and don't reset it back. Playing around with chdir is bad and causes issues.

    Fix this to instead use paths relative from the markdown file directory.

    bug 
    opened by captn3m0 0
  • Render Markdown inline

    Render Markdown inline

    Within the markdown, provide a way to declare pages that get rendered as stand-alone pages as well.

    <!-- This only goes in bookmark-->
    # Cover
    
    ![Cover](cover.pdf)
    
    # Colophon
    
    ```
    # Hobbit
    ## There and back again
    ## By JRR Tolkein
    ```{: inline=1}
    
    ![Foreword](foreword.pdf)
    

    Renders a cover, a single page with the 3 lines as above, and then the foreword. So the colophon ends up linking to the middle text section

    opened by captn3m0 3
  • Fetch HTML online and render

    Fetch HTML online and render

    # Title
    
    - [chapter 1](https://example.com/chapter1.html)
    - [chapter 2](https://example.com/chapter2.html)
    

    Download the source HTML, run it through readability, then render as PDF and merge accordingly.

    opened by captn3m0 0
Releases(v1.0.4)
  • v1.0.4(Dec 31, 2021)

    Changed

    • Switched from html5 to html5lib as a dependency, since the former is unmaintained.

    Added

    • Python 3.10 support

    Removed

    • Python 3.6 support
    Source code(tar.gz)
    Source code(zip)
  • v1.0.3(Jul 16, 2021)

    • Added tests and code coverage
    • PDFs can be directly fetched from Remote URLs
    • PDFs can be filtered to have start and end pages
    • Support for Python 3.6-3.8
    • Removed --cleanup argument, since that is default

    Published on PyPI: https://pypi.org/project/pystitcher/1.0.3/

    Source code(tar.gz)
    Source code(zip)
  • v1.0.2(Jul 16, 2021)

Owner
Nemo
Working at @razorpay
Nemo
PDFSanitizer - Renders possibly unsafe PDF files and outputs harmless PDF files

PDFSanitizer Renders possibly malicious PDF files and outputs harmless PDF files

null 9 Jan 30, 2022
Compare-pdf - A Flask driven restful API for comparing two PDF files

COMPARE-PDF A Flask driven restful API for comparing two PDF files. Description

Karthikeyan JC 3 Mar 13, 2022
A Python tool to generate a static HTML file that represents the internal structure of a PDF file

PDFSyntax A Python tool to generate a static HTML file that represents the internal structure of a PDF file At some point the low-level functions deve

Martin D. 394 Dec 30, 2022
Trata PDF para torná-lo compatível com PDF/X e com impressoras em escala de cinza.

tratapdf Trata PDF para torná-lo compatível com PDF/X e com impressoras em escala de cinza. dependências icc-profiles ghostscript visualizador de PDF

null 1 Nov 30, 2021
Convert PDF to AudioBook and Audio Speech to PDF

In this Python project, we will build a GUI-based PDF to Audio and Audio to PDF converter using the Tkinter, OS, path, pyttsx3, SpeechRecognition, PyPDF4, and Pydub libraries and the messagebox module of the Tkinter library.

RISHABH MISHRA 1 Feb 13, 2022
A backend for mdbook in Python for generating PDF based on Chrome DevTools Protocol.

mdbook-pdf A backend for mdbook written in Python for generating PDF based on Chrome DevTools Protocol. Python library dependency Usage Put mdbook-pdf

Hollow Man 49 Dec 27, 2022
Converting Html files to pdf using python script, pdfkit module and wkhtmltopdf.

Html-to-pdf-pdfkit-wkhtml- This repository has code for converting local html files and online html resources into pdf. It is an python script which u

Hemachandran P 1 Nov 9, 2021
this is simple program, that converts pdf file to png

author: a5892731 last update:2021-11-01 version: 1.1 resources: -https://pypi.org/project/pdf2image/ -https://github.com/oschwartz10612/poppler-window

null 1 Nov 1, 2021
DietPDF aims at reducing PDF file size while not degrading quality nor losing metadata

DietPDF aims at reducing PDF file size while not degrading quality nor losing metadata

Frédéric BISSON 6 Jul 27, 2022
Generate a bunch of malicious pdf files with phone-home functionality. Can be used with Burp Collaborator

Malicious PDF Generator ☠️ Generate ten different malicious pdf files with phone-home functionality. Can be used with Burp Collaborator. Used for pene

Jonas Lejon 1.9k Jan 1, 2023
Merge multiple PDF files into one.

PDF Merger Merge multiple PDF files into one. Usage % python pdf_merger.py -h usage: pdf_merger.py [-h] [-o OUTPUT] [-f [FILES ...]] optional argumen

Duo Apps 6 Oct 3, 2022
Python script that split PDF files.

Automatic PDF Splitter This script can create new single-page PDFs files from multipaged PDFs. Requirements Python 3.0+ # Debian distros sudo apt-get

Leandro Padula 5 Apr 2, 2022
borb is a library for reading, creating and manipulating PDF files in python.

borb is a library for reading, creating and manipulating PDF files in python.

Joris Schellekens 2.9k Jan 1, 2023
Program that locks/unlocks pdf files🐍

?? ?? PDFtools ?? ?? Programa que bloqueia/desbloqueia arquivos pdf Requisitos • Como usar • Capturas de Tela ?? Aviso ?? Altere os caminhos referente

João Victor Vilela dos Santos 1 Nov 4, 2021
pikepdf is a Python library for reading and writing PDF files.

A Python library for reading and writing PDF, powered by qpdf

null 1.6k Jan 3, 2023
Telegram bot that can do a lot of things related to PDF files.

Telegram PDF Bot A Telegram bot that can: Compress, crop, decrypt, encrypt, merge, preview, rename, rotate, scale and split PDF files Compare text dif

null 130 Dec 26, 2022
Convert MD files to PDF automatically (with CSS) 📄🚀

MD2PDF Action Convert MD files to PDF automatically (with CSS)! Converts a pattern described set of markdown files and converts them to pdf whilst app

Will Fantom 1 Feb 9, 2022
This book will take you on an exploratory journey through the PDF format, and the borb Python library.

This book will take you on an exploratory journey through the PDF format, and the borb Python library.

Joris Schellekens 281 Jan 1, 2023
Performing the following operations using python on PDF.

Python PDF Handling Tutorial Python is a highly versatile language with a huge set of libraries. It is a high level language with simple syntax. Pytho

Prajwol Lamichhane 131 Dec 16, 2022