Skip to content

Commit

Permalink
Add argument to override digital signatures
Browse files Browse the repository at this point in the history
  • Loading branch information
jbarlow83 committed Aug 12, 2023
1 parent 45added commit a6ce35b
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 3 deletions.
1 change: 1 addition & 0 deletions misc/completion/ocrmypdf.bash
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ __ocrmypdf_arguments()
--force-ocr (OCR documents that already have printable text)
--skip-text (skip OCR on any pages that already contain text)
--redo-ocr (redo OCR on any pages that seem to have OCR already)
--invalidate-digital-signatures (remove digital signatures from PDF)
--skip-big (skip OCR on pages larger than this many MPixels)
--optimize (select optimization level)
--jpeg-quality (JPEG quality [0..100])
Expand Down
1 change: 1 addition & 0 deletions misc/completion/ocrmypdf.fish
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ complete -c ocrmypdf -l remove-vectors -d "don't send vector objects to OCR"
complete -c ocrmypdf -s f -l force-ocr -d "OCR documents that already have printable text"
complete -c ocrmypdf -s s -l skip-ocr -d "skip OCR on pages that text, otherwise try OCR"
complete -c ocrmypdf -l redo-ocr -d "redo OCR on any pages that seem to have OCR already"
complete -c ocrmypdf -l invalidate-digital-signatures -d "invalidate digital signatures and allow OCR to proceed"

complete -c ocrmypdf -s k -l keep-temporary-files -d "keep temporary files (debug)"

Expand Down
7 changes: 5 additions & 2 deletions src/ocrmypdf/_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,12 @@ def validate_pdfinfo_options(context: PdfContext) -> None:
"This PDF contains dynamic XFA forms created by Adobe LiveCycle "
"Designer and can only be read by Adobe Acrobat or Adobe Reader."
)
if pdfinfo.has_acroform:
if pdfinfo.has_signature:
if pdfinfo.has_signature:
if options.invalidate_digital_signatures:
log.warning("All digital signatures will be invalidated")
else:
raise DigitalSignatureError()
if pdfinfo.has_acroform:
if options.redo_ocr:
raise InputFileError(
"This PDF has a user fillable form. --redo-ocr is not "
Expand Down
7 changes: 7 additions & 0 deletions src/ocrmypdf/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,13 @@ def get_parser():
help="Skip OCR on pages larger than the specified amount of megapixels, "
"but include skipped pages in final output",
)
ocrsettings.add_argument(
'--invalidate-digital-signatures',
action='store_true',
help="Normally, OCRmyPDF will refuse to OCR a PDF that has a digital "
"signature. This option allows OCR to proceed, but the digital signature "
"will be invalidated.",
)

advanced = parser.add_argument_group(
"Advanced", "Advanced options to control OCRmyPDF"
Expand Down
5 changes: 4 additions & 1 deletion src/ocrmypdf/pdfinfo/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -954,6 +954,10 @@ def __repr__(self):
class PdfInfo:
"""Get summary information about a PDF."""

_has_acroform: bool = False
_has_signature: bool = False
_needs_rendering: bool = False

def __init__(
self,
infile,
Expand Down Expand Up @@ -982,7 +986,6 @@ def __init__(
detailed_analysis=detailed_analysis,
)
self._needs_rendering = pdf.Root.get(Name.NeedsRendering, False)
self._has_acroform = False
if Name.AcroForm in pdf.Root:
if len(pdf.Root.AcroForm.get(Name.Fields, [])) > 0:
self._has_acroform = True
Expand Down
6 changes: 6 additions & 0 deletions tests/test_acroform.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,9 @@ def digitally_signed(acroform, outdir):
def test_digital_signature(digitally_signed, no_outpdf):
with pytest.raises(ocrmypdf.exceptions.DigitalSignatureError):
check_ocrmypdf(digitally_signed, no_outpdf)


def test_digital_signature_invalidate(digitally_signed, no_outpdf):
check_ocrmypdf(
digitally_signed, no_outpdf, '--force-ocr', '--invalidate-digital-signatures'
)

0 comments on commit a6ce35b

Please sign in to comment.