Skip to content

ENH: Support detection of digital signatures #2655

@macdeport

Description

@macdeport

Explanation

IMHO pypdf deserves that the is_encrypted property be completed by is_signed (Digitally signed).

Code Example

How would your feature be used? (Remove this if it is not applicable.)

import pypdf

def is_signed(pdf_file_path):
    reader = pypdf.PdfReader(pdf_file_path)
    root = reader.trailer['/Root']; l_signed = False
    if acroform := root.get('/AcroForm'):
        if acroform and (sig := acroform.get('/SigFlags')):
            l_signed = bool(sig & 1)
    return l_signed
# inspired by the [OCRmyPDF](https://github.com/ocrmypdf/OCRmyPDF/) code

# Use:
reader = PdfReader(pdf_file)

if reader.is_signed:
    print(f'{pdf_file!r} is digitaly signed...n')

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions