mirror of
				https://github.com/ocrmypdf/OCRmyPDF.git
				synced 2025-11-04 03:40: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 subprocess import Popen, check_call, PIPE, CalledProcessError, \
 | 
			
		||||
    TimeoutExpired, check_output, STDOUT
 | 
			
		||||
from subprocess import CalledProcessError, \
 | 
			
		||||
     check_output, STDOUT
 | 
			
		||||
try:
 | 
			
		||||
    from subprocess import DEVNULL
 | 
			
		||||
except ImportError:
 | 
			
		||||
@ -748,29 +748,7 @@ def copy_final(
 | 
			
		||||
def validate_pdfa(
 | 
			
		||||
        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
 | 
			
		||||
    return qpdf.check(input_file, log)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# @active_if(ocr_required and options.exact_image)
 | 
			
		||||
 | 
			
		||||
@ -8,6 +8,30 @@ import os
 | 
			
		||||
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):
 | 
			
		||||
    args_qpdf = [
 | 
			
		||||
        'qpdf', input_file, output_file
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user