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)

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 09, 2022
Generate a preview image for a PDF.

PDF ➡️ Preview A simple tool to save me time on Illustrator. Generates a preview image for a PDF file. Useful for sneak peeks to academic publications

David Chuan-En Lin 51 Sep 22, 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

1 Nov 30, 2021
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 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
pdf_sprinkles: sprinkles text in your PDFs

pdf_sprinkles: sprinkles text in your PDFs pdf_sprinkles remotely OCRs a PDF with Google Cloud Document AI, and returns the result as a PDF with searc

Will Angley 2 Dec 17, 2021
pystitcher stitches your PDF files together, generating nice customizable bookmarks for you using a declarative markdown file as input

pystitcher pystitcher stitches your PDF files together, generating nice customizable bookmarks for you using a declarative input in the form of a mark

Nemo 387 Dec 10, 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
Excalibur: A web interface to extract tabular data from PDFs

Excalibur: A web interface to extract tabular data from PDFs Excalibur is a web interface to extract tabular data from PDFs, written in Python 3! It i

1.2k Jan 04, 2023
Convert given source code into .pdf with syntax highlighting and more features

Code2pdf 📠 Convert given source code into .pdf with syntax highlighting and more features Build Status Version Downloads Python Demo Installation Bui

Tushar Gautam 343 Jan 05, 2023
Simple pdf editor while preserving structure and format.

SIMPdf Simple pdf editor while preserving structure and format.

Shashwat Singh 242 Jan 04, 2023
Extract the table in the PDF,outputs the data similar to the json format

extract the table in the PDF,outputs the data similar to the json format

3 Nov 25, 2021
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
Simple python tool created for downloading PDF.

PDFdownloader Usage Open PDF in full-screen mode Run scan.exe Enter how many pages you want to scan Focus PDF After scanning is done, run merge.exe En

5 Oct 27, 2021
CLI tool to generate pdf invoices written in python

invoicepy CLI invoice tool, store and print invoices as pdf. save companies and customers for later use. installation pip install invoicepy config co

Adam Wojtczak 9 Aug 01, 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 01, 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
PDFSanitizer - Renders possibly unsafe PDF files and outputs harmless PDF files

PDFSanitizer Renders possibly malicious PDF files and outputs harmless PDF files

9 Jan 30, 2022
Scans pdfs for links written in plaintext and checks if they are active or returns an error code.

Scans pdfs for links written in plaintext and checks if they are active or returns an error code. It then generates a report of its findings. Extract references (pdf, url, doi, arxiv) and metadata fr

Marshal Miller 22 Nov 21, 2022
Python bindings for MuPDF's rendering library.

PyMuPDF 1.19.3 Release date: December 15, 2021 On PyPI since August 2016: Author Jorj X. McKie, based on original code by Ruikai Liu. Introduction PyM

Jorj X. McKie 0 Nov 03, 2022