o
    @@i)A                     @   sR   d Z ddlZddlmZ ddlmZ ddlmZ G dd dZG dd	 d	eZ	dS )
zH
This class represents the meta-information belonging to a PDF document
    N)DecimalName)ConformanceLevelc                       sj  e Zd ZdZd) fddZdefddZdeje	 fd	d
Z
deje fddZdeje	 fddZdeje	 fddZdeje fddZdejeje	  fddZdeje	 fddZdeje	 fddZdeje	 fddZdeje fddZdeje	 fddZdeje	 fdd Zdeje	 fd!d"Zdeje	 fd#d$Zdefd%d&Zdefd'd(Z  ZS )*DocumentInfozP
    This class represents the meta-information belonging to a PDF document
    documentDocumentc                    s   t    || _d S N)super__init__	_documentselfr   	__class__ \/home/ubuntu/transcripts/venv/lib/python3.10/site-packages/borb/pdf/trailer/document_info.pyr      s   

zDocumentInfo.__init__returnc                 C   s   t  )z
        This method verifies the signatures in the Document,
        it returns True if the signatures match the digest of the Document
        (or if the Document has no signatures), False otherwise
        )NotImplementedErrorr   r   r   r   check_signatures#   s   zDocumentInfo.check_signaturesc                 C   &   z| j d d d d W S    Y dS )V
        (Optional; PDF 1.1) The name of the person who created the document.
        XRefTrailerInfoAuthorNr   r   r   r   r   
get_author,      zDocumentInfo.get_authorc                 C   s   | j jS )aB  
        This function returns the ConformanceLevel that was
        set for writing operations upon creating the Document instance.
        This allows the user to specify whether they want to enable things like tagging.
        A document that was already tagged, and read by borb will of course remain tagged.
        A document that was not tagged, will similarly not magically be provided with tags.
        This ConformanceLevel only applies to Document instances that were created by borb.
        :return:    the ConformanceLevel to be used when writing the PDF
        )r   _conformance_level_upon_creater   r   r   r   !get_conformance_level_upon_create5   s   z.DocumentInfo.get_conformance_level_upon_createc                 C   r   )   
        (Optional) The date and time the document was created, in human-
        readable form (see 7.9.4, “Dates”).
        r   r   r   CreationDateNr   r   r   r   r   get_creation_dateB      zDocumentInfo.get_creation_datec                 C   r   )
        (Optional) If the document was converted to PDF from another format,
        the name of the conforming product that created the original
        document from which it was converted.
        r   r   r   CreatorNr   r   r   r   r   get_creatorL      zDocumentInfo.get_creatorc                 C   s   | j ddS )zP
        This function returns the filesize (in bytes) of this Document
        FileSizeN)r   getr   r   r   r   get_file_sizeW   s   zDocumentInfo.get_file_sizec                 C   s@   d| j v rd| j d v rd| j d d v r| j d d d S dS )u  
        File identifiers shall be defined by the optional ID entry in a PDF file’s trailer dictionary (see 7.5.5, “File Trailer”).
        The ID entry is optional but should be used. The value of this entry shall be an array of two byte strings. The
        first byte string shall be a permanent identifier based on the contents of the file at the time it was originally
        created and shall not change when the file is incrementally updated. The second byte string shall be a
        changing identifier based on the file’s contents at the time it was last updated. When a file is first written, both
        identifiers shall be set to the same value. If both identifiers match when a file reference is resolved, it is very
        likely that the correct and unchanged file has been found. If only the first identifier matches, a different version
        of the correct file has been found.
        r   r   IDNr   r   r   r   r   get_ids]   s
   
zDocumentInfo.get_idsc                 C   r   )L
        (Optional; PDF 1.1) Keywords associated with the document.
        r   r   r   KeywordsNr   r   r   r   r   get_keywordsp   r   zDocumentInfo.get_keywordsc                 C   r   )ao  
        (Optional; PDF 1.4) A language identifier that shall specify the
        natural language for all text in the document except where
        overridden by language specifications for structure elements or
        marked content (see 14.9.2, "Natural Language Specification"). If
        this entry is absent, the language shall be considered unknown.
        r   r   RootLangNr   r   r   r   r   get_languagey   s   zDocumentInfo.get_languagec                 C   r   )   
        Required if PieceInfo is present in the document catalogue;
        otherwise optional; PDF 1.1) The date and time the document was
        most recently modified, in human-readable form (see 7.9.4, “Dates”).
        r   r   r   ModDateNr   r   r   r   r   get_modification_date   r)   z"DocumentInfo.get_modification_datec                 C   s   | j d d d d d S )zK
        This function returns the number of pages in the Document
        r   r   r2   PagesCountr   r   r   r   r   get_number_of_pages   s   z DocumentInfo.get_number_of_pagesc                 C   s(   |   sg S dd | jd d d D S )u   
        This function returns the name(s) of the optional content group(s),
        suitable for presentation in a reader’s user interface
        c                 S   s    g | ]}d |v rt |d  qS r   )str).0xr   r   r   
<listcomp>   s
    
zADocumentInfo.get_optional_content_group_names.<locals>.<listcomp>r   r   OCProperties)has_optional_contentr   r   r   r   r    get_optional_content_group_names   s
   z-DocumentInfo.get_optional_content_group_namesc                 C   r   )
        (Optional) If the document was converted to PDF from another format,
        the name of the conforming product that converted it to PDF.
        r   r   r   ProducerNr   r   r   r   r   get_producer   r%   zDocumentInfo.get_producerc                 C   r   )B
        (Optional; PDF 1.1) The subject of the document.
        r   r   r   SubjectNr   r   r   r   r   get_subject   r   zDocumentInfo.get_subjectc                 C   r   )=   
        (Optional; PDF 1.1) The document’s title.
        r   r   r   TitleNr   r   r   r   r   	get_title   r   zDocumentInfo.get_titlec                 C   s   d| j d d v S )a(  
        Optional content (PDF 1.5) refers to sub-clauses of content in a PDF document that can be selectively viewed
        or hidden by document authors or consumers. This capability is useful in items such as CAD drawings, layered
        artwork, maps, and multi-language documents.
        r?   r   r   r   r   r   r   r   r@      s   z!DocumentInfo.has_optional_contentc                 C   s   | j d d d }tdd |tdi tdg D }tdd |tdi tdg D }|td	i td
ddu}|pH|pH|S )z]
        This function returns True if this Document has signatures, False otherwise
        r   r   r2   c                 S   s.   g | ]}t |tr|td dtdkqS )FTNSig
isinstancedictr+   r   r<   dr   r   r   r>      s    z/DocumentInfo.has_signatures.<locals>.<listcomp>AcroFormFieldsc                 S   s:   g | ]}t |tr|td dtdkotd|v qS )rK   NrL   DocMDPrM   rP   r   r   r   r>      s    "PermUR3N)r   anyr+   r   )r   catalog_dicthas_approval_signatureshas_certification_signaturehas_usage_rights_signaturesr   r   r   has_signatures   s$   zDocumentInfo.has_signaturesr   r   )__name__
__module____qualname____doc__r   boolr   typingOptionalr;   r   r   r!   r$   r(   r   r,   Listr.   r1   r4   r7   r:   rA   rD   rG   rJ   r@   r\   __classcell__r   r   r   r   r      s(    		
	
		r   c                       s&  e Zd ZdZd! fddZdeje fddZdeje fd	d
Z	deje fddZ
deje fddZdeje fddZdeje fddZdeje fddZdeje fddZdeje fddZdeje fddZdeje fddZdeje fddZdeje fdd Z  ZS )"XMPDocumentInfozV
    This class represents the (XMP) meta-information belonging to a PDF document
    r   r   c                    s   t t| | d S r	   )r
   rg   r   r   r   r   r   r      s   zXMPDocumentInfo.__init__r   c                 C   :   z| j d d d d dd d d jW S    Y dS )r   r   r   r2   Metadataz.//{*}creatorr   Nr   findalltextr   r   r   r   r        zXMPDocumentInfo.get_authorc                 C   J   zt tdd | jd d d d dd j D d	W S    Y d	S )
r"   c                 S      g | ]\}}| d r|qS )
CreateDateendswithr<   kvr   r   r   r>         z5XMPDocumentInfo.get_creation_date.<locals>.<listcomp>r   r   r2   ri   .//{*}Descriptionr   Nnextiterr   rk   attribitemsr   r   r   r   r$         z!XMPDocumentInfo.get_creation_datec                 C   rn   )
r&   c                 S   ro   )CreatorToolrq   rs   r   r   r   r>   3  rv   z/XMPDocumentInfo.get_creator.<locals>.<listcomp>r   r   r2   ri   rw   r   Nrx   r   r   r   r   r(   *      zXMPDocumentInfo.get_creatorc                 C   2   z| j d d d d dd jW S    Y dS )z
        The common identifier for all versions and renditions of a document.
        It should be based on a UUID; see Document and Instance IDs.
        r   r   r2   ri   z.//{*}DocumentIDr   Nrj   r   r   r   r   get_document_idB     zXMPDocumentInfo.get_document_idc                 C   r   )z
        An identifier for a specific incarnation of a document, updated each time a file is saved.
        It should be based on a UUID; see Document and Instance IDs.
        r   r   r2   ri   z.//{*}InstanceIDr   Nrj   r   r   r   r   get_instance_idP  r   zXMPDocumentInfo.get_instance_idc                 C   rn   )
r/   c                 S   ro   )r0   rq   rs   r   r   r   r>   e  rv   z0XMPDocumentInfo.get_keywords.<locals>.<listcomp>r   r   r2   ri   rw   r   Nrx   r   r   r   r   r1   ^  s    zXMPDocumentInfo.get_keywordsc                 C   r   )u   
        (Optional) The date and time the metadata for this document was created, in human-
        readable form (see 7.9.4, “Dates”).
        r   r   r2   ri   z.//{*}MetadataDater   Nrj   r   r   r   r   get_metadata_datet  r   z!XMPDocumentInfo.get_metadata_datec                 C   rn   )
r5   c                 S   ro   )
ModifyDaterq   rs   r   r   r   r>     rv   z9XMPDocumentInfo.get_modification_date.<locals>.<listcomp>r   r   r2   ri   rw   r   Nrx   r   r   r   r   r7     r   z%XMPDocumentInfo.get_modification_datec                 C   r   )zb
        Refer to Part 1, Data Model, Serialization, and Core Properties, for definition.
        r   r   r2   ri   z.//{*}OriginalDocumentIDr   Nrj   r   r   r   r   get_original_document_id     z(XMPDocumentInfo.get_original_document_idc                 C   rn   )
rB   c                 S   ro   )rC   rq   rs   r   r   r   r>     rv   z0XMPDocumentInfo.get_producer.<locals>.<listcomp>r   r   r2   ri   rw   r   Nrx   r   r   r   r   rD     r}   zXMPDocumentInfo.get_producerc                 C   r   )zg
        (Optional; PDF 1.1) The name of the person/software who/which published the document.
        r   r   r2   ri   z.//{*}publisherr   Nrj   r   r   r   r   get_publisher  r   zXMPDocumentInfo.get_publisherc                 C   rh   )rE   r   r   r2   ri   z.//{*}descriptionr   Nrj   r   r   r   r   rG     rm   zXMPDocumentInfo.get_subjectc                 C   rh   )rH   r   r   r2   ri   z.//{*}titler   Nrj   r   r   r   r   rJ     rm   zXMPDocumentInfo.get_titler]   )r^   r_   r`   ra   r   rc   rd   r;   r   r$   r(   r   r   r1   r   r7   r   rD   r   rG   rJ   rf   r   r   r   r   rg      s     rg   )
ra   rc   decimalr   borb.io.read.typesr   borb.io.write.conformance_levelr   r   rg   r   r   r   r   <module>   s    e