File: //lib/python3/dist-packages/ocrmypdf/__pycache__/_pipeline.cpython-38.pyc
U
��Z^Av � @ s d dl Z d dlZd dlZd dlmZmZ d dlmZ d dlmZ d dl Z d dl
Z
d dlmZ d dl
mZ ddlmZ dd lmZ dd
lmZ ddlmZmZmZmZmZ ddlmZmZ dd
lmZ ddl m!Z! ddl"m"Z" ddl#m$Z$ ddl%m&Z&m'Z'm(Z( dZ)dd� Z*dTdd�Z+dd� Z,dUdd�Z-dd� Z.dd � Z/d!d"� Z0d#d$� Z1d%d&� Z2d'd(� Z3d)d*� Z4d+d,� Z5dVd.d/�Z6d0d1� Z7d2d3� Z8d4d5� Z9d6d7� Z:d8d9� Z;d:d;� Z<d<d=� Z=d>d?� Z>d@dA� Z?dBdC� Z@dDdE� ZAdFdG� ZBdHdI� ZCdJdK� ZDdLdM� ZEdNdO� ZFdPdQ� ZGdRdS� ZHdS )W� N)�datetime�timezone)�Path)�copyfileobj)�encode_pdf_date)�Image� )� leptonica)�PROGRAM_NAME)�__version__)�DpiError�EncryptedPdfError�InputFileError�PriorOcrFoundError�UnsupportedImageFormatError)�ghostscript� tesseract)�safe_symlink)�
HocrTransform)�optimize)�generate_pdfa_ps)�
Colorspace�Encoding�PdfInfoi� c
C s� |� d� zt�| �}W nB tk
rZ } z$|�t|��| |j�� t� |�W 5 d }~X Y nX |�� |� d� d|j kr�|j d dkr�|j s�|� d|j
� |� d|j d � |�d� t� �n&|j s�|� d|j
� |�d� t� �|jd k�r|�d
� t� �d|j k�rB|jdk�r&|� d
� n|jdk�rB|�d� t� �W 5 Q R X z`|� d� t
j}|j �rxt
�|j |j f�}t|d��}t
j| |d|d� W 5 Q R X |� d� W n8 t
jk
�r� } z|�|� t� |�W 5 d }~X Y nX d S )Nz6Input file is not a PDF, checking if it is an image...zInput file is an image�dpi)�` r zImage size: (%d, %d)zImage resolution: (%d, %d)z�Input file is an image, but the resolution (DPI) is not credible. Estimate the resolution at which the image was scanned and specify it using --image-dpi.z�Input file is an image, but has no resolution (DPI) in its metadata. Estimate the resolution at which image was scanned and specify it using --image-dpi.)ZRGBAZLAzEThe input image has an alpha channel. Remove the alpha channel first.Z
iccprofileZRGBz-Input image has no ICC profile, assuming sRGBZCMYKz/Input CMYK image has no ICC profile, not usablez+Image seems valid. Try converting to PDF...�wbF)�
layout_fun�
with_pdfrw�outputstreamz,Successfully converted to PDF, processing...)�infor �open�EnvironmentError�error�str�replace�
input_filer � image_dpi�sizer �mode�img2pdfZdefault_layout_fun�get_fixed_dpi_layout_fun�convertZImageOpenError)r&