File: //usr/lib/python3/dist-packages/ocrmypdf/__pycache__/pdfa.cpython-38.pyc
U
��Z^W � @ s^ d Z ddlZddlmZ ddlmZ ddlZddlZdZe� de�Z
dZd
d d
�Zdd� Z
dS )am
Generate a PDFMARK file for Ghostscript >= 9.14, for PDF/A conversion
pdfmark is an extension to the Postscript language that describes some PDF
features like bookmarks and annotations. It was originally specified Adobe
Distiller, for Postscript to PDF conversion:
https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/pdfmark_reference.pdf
Ghostscript uses pdfmark for PDF to PDF/A conversion as well. To use Ghostscript
to create a PDF/A, we need to create a pdfmark file with the necessary metadata.
This takes care of the many version-specific bugs and pecularities in
Ghostscript's handling of pdfmark.
� N)�Path)�Templatez
data/sRGB.iccZocrmypdfa� %!
% Define an ICC profile :
/ICCProfile $icc_profile
def
[/_objdef {icc_PDFA} /type /stream /OBJ pdfmark
[{icc_PDFA} << /N 3 >> /PUT pdfmark
[{icc_PDFA} ICCProfile /PUT pdfmark
% Define the output intent dictionary :
[/_objdef {OutputIntent_PDFA} /type /dict /OBJ pdfmark
[{OutputIntent_PDFA} <<
/Type /OutputIntent % Must be so (the standard requires).
/S /GTS_PDFA1 % Must be so (the standard requires).
/DestOutputProfile {icc_PDFA} % Must be so (see above).
/OutputConditionIdentifier ($icc_identifier)
>> /PUT pdfmark
[{Catalog} <</OutputIntents [ {OutputIntent_PDFA} ]>> /PUT pdfmark
�sRGBc C sb |dkrt }ntd��t|��� }tj|dd��d�}tt�}|j ||d�}t| �j
|dd� | S )a� Create a Postscript pdfmark file for Ghostscript PDF/A conversion
A pdfmark file is a small Postscript program that provides some information
Ghostscript needs to perform PDF/A conversion. The only information we put
in specifies that we want the file to be a PDF/A, and we want to Ghostscript
to convert objects to the sRGB colorspace if it runs into any object that
it decides must be converted.
See the Adobe pdfmark Reference for details:
https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/pdfmark_reference.pdf
:param target_filename: filename to save
:param icc: ICC identifier such as 'sRGB'
r zOnly supporting sRGBT)Zadobe�ascii)�icc_profileZicc_identifier)�encoding)�SRGB_ICC_PROFILE�NotImplementedErrorr Z
read_bytes�base64Z a85encode�decoder �pdfa_def_templateZ
substituteZ
write_text)Ztarget_filenameZiccr Zbytes_icc_profile�tZps� r �//usr/lib/python3/dist-packages/ocrmypdf/pdfa.py�generate_pdfa_psG s r c
C s� t �| ��r}|�� }|js2dddd�W 5 Q R � S ddddd d
ddh}d
|j� �}i }|j|krpd|d<