HEX
Server: Apache
System: Linux srv1.prosuiteplus.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: prosuiteplus (1001)
PHP: 8.3.20
Disabled: NONE
Upload Files
File: //lib/python3/dist-packages/ocrmypdf/__pycache__/pdfa.cpython-38.pyc
U

��Z^W�@s^dZddlZddlmZddlmZddlZddlZdZe�	de�Z
dZd
d	d
�Zdd�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
�sRGBcCsb|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'
    rzOnly supporting sRGBT)Zadobe�ascii)�icc_profileZicc_identifier)�encoding)�SRGB_ICC_PROFILE�NotImplementedErrorrZ
read_bytes�base64Z	a85encode�decoder�pdfa_def_templateZ
substituteZ
write_text)Ztarget_filenameZiccrZbytes_icc_profile�tZps�r�//usr/lib/python3/dist-packages/ocrmypdf/pdfa.py�generate_pdfa_psGsrc
Cs�t�|��r}|��}|js2dddd�W5QR�Sddddd	d
ddh}d
|j��}i}|j|krpd|d<d|d<||d<W5QRX|S)z�Determines if the file claims to be PDF/A compliant

    This only checks if the XMP metadata contains a PDF/A marker. It does not
    do full PDF/A validation.
    F�pdfzNo PDF/A metadata in XMP)�pass�output�conformanceZ1AZ1BZ2AZ2BZ2UZ3AZ3BZ3UzPDF/A-TrZpdfarr)�pikepdf�openZ
open_metadataZpdfa_status)�filenamerZpdfmetaZvalid_part_conformsrZ	pdfa_dictrrr�file_claims_pdfais�
r)r)�__doc__r
�pathlibr�stringrrZ
pkg_resourcesZICC_PROFILE_RELPATHZresource_filenamerrrrrrrr�<module>s
"