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)

A simple pdf size compressing telegram robot witten in python.

Pdf Compressor Telegram Bot ##About : A simple pdf size compressing telegram robot witten in python. Mostly useful for digital documentation. Deploy t

Renjith Mangal 22 Oct 28, 2022
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 03, 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
Camelot is a Python library that can help you extract tables from PDFs!

A Python library to extract tabular data from PDFs

1.8k Jan 03, 2023
Produce pdf in python backend from simple bootstrap vue frontend and download to browser

vollmacht produce pdf in python backend from simple bootstrap vue frontend and download to browser Frontend in one file with bootstrap-vue (allthough

Otto 1 Nov 08, 2020
PyPDF2 is a pure-python PDF library capable of splitting, merging together, cropping, and transforming the pages of PDF files.

PyPDF2 is a pure-python PDF library capable of splitting, merging together, cropping, and transforming the pages of PDF files. It can also add custom data, viewing options, and passwords to PDF files

Matthew Stamy 5k Jan 04, 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

130 Dec 26, 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
Pdfencrypt is a tool to encrypt/lock PDFs

Pdfencrypt Pdfencrypt is a tool to encrypt/lock PDFs Installation $ apt update $ apt upgrade $ apt install git $ apt install python $ git clone https:

Anontemitayo 5 Nov 28, 2021
Table automatically extraction from PDF Document

PDF Table Extractor Table automatically extraction from PDF Document Our Icon 📌 Name : PDF Table Extractor 📌 Authors : Minku Koo Jiyong Park 📌 Deve

1 Jan 10, 2022
Camelot is a Python library that makes it easy for anyone to extract tables from PDF files

Camelot: PDF Table Extraction for Humans Camelot is a Python library that makes it easy for anyone to extract tables from PDF files! Note: You can als

Atlan Technologies Pvt Ltd 3.3k Jan 06, 2023
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 01, 2023
Svg2pdfgen - Svg To PDF gen with python

Svg2pdfgen - Svg To PDF gen with python

Robert Urbańczyk 3 May 30, 2022
Split given PDF document into 4 page groups and convert them to booklet format

PUTO: PDF to Booklet converter Split given PDF document into 4 page groups and convert them to booklet format. It creates a PDF like shown below: Fir

3 Mar 12, 2022
An application which enables the users to perform simple yet intriguing PDF operations

AstutePDF A repository containing the GUI for an application which enables the users to perform simple yet intriguing PDF operations. These include, M

Raghav S 5 Jan 22, 2022
rst2pdf: Use a text editor. Make a PDF.

rst2pdf: Use a text editor. Make a PDF.

rst2pdf 487 Jan 06, 2023
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 modul

RISHABH MISHRA 1 Feb 13, 2022
Busca no nome e conteúdo de arquivos PDF no diretório e subdiretórios.

PDF Finder Este script auxilia na pesquisa em pastas com inúmeros arquivos PDF. A pesquisa é feita em todos os arquivos do doretório e subdiretórios.

William Pilger 1 Nov 27, 2021
Simple pdf editor while preserving structure and format.

SIMPdf Simple pdf editor while preserving structure and format.

Shashwat Singh 242 Jan 04, 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 04, 2021