mirror of
https://github.com/ocrmypdf/OCRmyPDF.git
synced 2025-11-03 03:10:19 +00:00
Move PDF validation check to qpdf.py
This commit is contained in:
parent
e76ae8c46c
commit
5d8167b232
@ -17,8 +17,8 @@ from PIL import Image
|
|||||||
|
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
from subprocess import Popen, check_call, PIPE, CalledProcessError, \
|
from subprocess import CalledProcessError, \
|
||||||
TimeoutExpired, check_output, STDOUT
|
check_output, STDOUT
|
||||||
try:
|
try:
|
||||||
from subprocess import DEVNULL
|
from subprocess import DEVNULL
|
||||||
except ImportError:
|
except ImportError:
|
||||||
@ -748,29 +748,7 @@ def copy_final(
|
|||||||
def validate_pdfa(
|
def validate_pdfa(
|
||||||
input_file,
|
input_file,
|
||||||
log):
|
log):
|
||||||
|
return qpdf.check(input_file, log)
|
||||||
args_qpdf = [
|
|
||||||
'qpdf',
|
|
||||||
'--check',
|
|
||||||
input_file
|
|
||||||
]
|
|
||||||
|
|
||||||
try:
|
|
||||||
check_output(args_qpdf, stderr=STDOUT, universal_newlines=True)
|
|
||||||
except CalledProcessError as e:
|
|
||||||
if e.returncode == 2:
|
|
||||||
print("{0}: not a valid PDF, and could not repair it.".format(
|
|
||||||
options.input_file))
|
|
||||||
print("Details:")
|
|
||||||
print(e.output)
|
|
||||||
elif e.returncode == 3:
|
|
||||||
log.info("qpdf --check returned warnings:")
|
|
||||||
log.info(e.output)
|
|
||||||
else:
|
|
||||||
print(e.output)
|
|
||||||
return False
|
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
# @active_if(ocr_required and options.exact_image)
|
# @active_if(ocr_required and options.exact_image)
|
||||||
|
|||||||
@ -8,6 +8,30 @@ import os
|
|||||||
from . import ExitCode
|
from . import ExitCode
|
||||||
|
|
||||||
|
|
||||||
|
def check(input_file, log):
|
||||||
|
args_qpdf = [
|
||||||
|
'qpdf',
|
||||||
|
'--check',
|
||||||
|
input_file
|
||||||
|
]
|
||||||
|
|
||||||
|
try:
|
||||||
|
check_output(args_qpdf, stderr=STDOUT, universal_newlines=True)
|
||||||
|
except CalledProcessError as e:
|
||||||
|
if e.returncode == 2:
|
||||||
|
print("{0}: not a valid PDF, and could not repair it.".format(
|
||||||
|
input_file))
|
||||||
|
print("Details:")
|
||||||
|
print(e.output)
|
||||||
|
elif e.returncode == 3:
|
||||||
|
log.info("qpdf --check returned warnings:")
|
||||||
|
log.info(e.output)
|
||||||
|
else:
|
||||||
|
print(e.output)
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
def repair(input_file, output_file, log):
|
def repair(input_file, output_file, log):
|
||||||
args_qpdf = [
|
args_qpdf = [
|
||||||
'qpdf', input_file, output_file
|
'qpdf', input_file, output_file
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user