Skip to content

Instantly share code, notes, and snippets.

View matsavage's full-sized avatar
👋

Mathew Savage matsavage

👋
View GitHub Profile
@matsavage
matsavage / pdf_flatten.py
Last active May 15, 2024 20:29
Subclass to flatten form objects
from pypdf import PdfReader, PdfWriter
from pypdf.generic import NameObject, NumberObject, TextStringObject, DictionaryObject, StreamObject, ArrayObject
class CustomPdfWriter(PdfWriter):
def flatten_form_fields(self):
"""
Flattens the form fields in the PDF, making them part of the content and non-editable.
"""
for page in self.pages: