
    .ic                     ^   d Z ddlZddlZddlmZ ddlmZ ddlm	Z
 ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ  ej        e          Z G d	 d
e
j                  Zd Z G d de
j                  Z G d de
j                  Z G d de
j                  Z G d de
j                  ZdS ))PdfDocument
PdfFormEnv
PdfXObjectPdfBookmarkPdfDest    N)Path)PDFIUM_INFO)PdfiumError)PdfPage)	PdfObject)PdfAttachmentc                   8    e Zd ZdZd' fd	Zd Zd Z fdZed             Z	e
d	             Zd
 Zd Zd Zd Zed             Zd(dZd Zd Zd Zd)dZej        fdZd Zd ZdZd*dZd Zd Zd Z d Z!d Z"d(dZ#d  Z$d+d!Z%d" Z&d# Z'd$ Z(	 	 	 	 d,d&Z) xZ*S )-r   a  
    Document helper class.
    
    Parameters:
        input_data (str | pathlib.Path | bytes | ctypes.Array | typing.BinaryIO | FPDF_DOCUMENT):
            The input PDF given as file path, bytes, ctypes array, byte stream, or raw PDFium document handle.
            A byte stream is defined as an object that implements ``seek() tell() read() readinto()``.
        password (str | None):
            A password to unlock the PDF, if encrypted. Otherwise, None or an empty string may be passed.
            If a password is given but the PDF is not encrypted, it will be ignored (as of PDFium 5418).
        autoclose (bool):
            Whether byte stream input should be automatically closed on finalization.
    
    Raises:
        PdfiumError: Raised if the document failed to load. The exception is annotated with the reason reported by PDFium (via message and :attr:`~.PdfiumError.err_code`).
        FileNotFoundError: Raised if an invalid or non-existent file path was given.
    
    Hint:
        * Documents may be used in a ``with``-block, closing the document on context manager exit.
          This is recommended when *input_data* is a file path, to safely and immediately release the bound file handle.
        * :func:`len` may be called to get a document's number of pages.
        * Pages may be loaded using list index access.
        * Looping over a document will yield its pages from beginning to end.
        * The ``del`` keyword and list index access may be used to delete pages.
    
    Attributes:
        raw (FPDF_DOCUMENT):
            The underlying PDFium document handle.
        formenv (PdfFormEnv | None):
            Form env, if the document has forms and :meth:`.init_forms` was called.
    NFc                    t          |t                    rt          |          }t          |t                    rI|                                                                }|                                st          |          || _        || _        || _	        g | _
        g | _        d | _        t          | j        t          j                  r| j        | _        nIt!          | j        | j        | j	                  \  | _        }}| xj
        |z  c_
        | xj        |z  c_        t#                                          t&          j        | j
        | j                   d S N)
isinstancestrr   
expanduserresolveis_fileFileNotFoundError_input	_password
_autoclose_data_holder_data_closerformenvpdfium_cFPDF_DOCUMENTraw	_open_pdfsuper__init__r   _close_impl)selfinputpassword	autocloseto_holdto_close	__class__s         W/var/www/html/analyses/venv/lib/python3.11/site-packages/pypdfium2/_helpers/document.pyr"   zPdfDocument.__init__6   s0   eS!! 	 KKEeT"" 	/$$&&..00E==?? /'...!#dk8#9:: 	*{DHH*3DKQUQ`*a*a'DHgx()0$2CTEVWWWWW    c                     | S r    r$   s    r+   	__enter__zPdfDocument.__enter__S   s    r,   c                 .    |                                   d S r   )close)r$   _s     r+   __exit__zPdfDocument.__exit__V   s    

r,   c                 
   t          | j        t                    r"t          t	          | j                            }nt          | j        t
                    r&dt          t          | j                             d}nYt          | j        t          j	                  r&dt          t          | j                             d}nt          | j                  }t                                                      d d          d| dS )Nz<bytes object at >z<FPDF_DOCUMENT at z from )r   r   r   reprr   byteshexidr   r   r!   __repr__)r$   input_rr*   s     r+   r<   zPdfDocument.__repr__Z   s    dk4(( 	(C,,..GGU++ 	(A#boo*>*>AAAGGX%;<< 	(B3r$++?+?BBBGG4;''G''""$$SbS);;;;;;r,   c                     d S r   r.   r/   s    r+   parentzPdfDocument.parentf   s    tr,   c                     t          j        |            |D ]}t          |           |D ]}|                                 |                                 |                                 d S r   )r   FPDF_CloseDocumentr;   r2   clear)r   data_holderdata_closerdatas       r+   r#   zPdfDocument._close_implk   sw    #C((( 	 	DtHHHH 	 	DJJLLLLr,   c                 *    t          j        |           S r   )r   FPDF_GetPageCountr/   s    r+   __len__zPdfDocument.__len__v   s    )$///r,   c              #   \   K   t          t          |                     D ]}| |         V  d S r   )rangelenr$   is     r+   __iter__zPdfDocument.__iter__y   s<      D		## 	 	Aq'MMMM	 	r,   c                 ,    |                      |          S r   )get_pagerL   s     r+   __getitem__zPdfDocument.__getitem__}   s    }}Qr,   c                 0    |                      |           d S r   )del_pagerL   s     r+   __delitem__zPdfDocument.__delitem__   s    ar,   c                 >    t          j                    } | |          S )zJ
        Returns:
            PdfDocument: A new, empty document.
        )r   FPDF_CreateNewDocument)clsnew_pdfs     r+   newzPdfDocument.new   s      133s7||r,   c                 2   |                                  }|t          j        k    s| j        rdS |sbdt          j        v r?t          j        d          }t          j        ddt          j	        |                    }nt          j        d          }t          j
        | |          }|st          d|  d	          t          || |          | _        |                     | j                   |t          j        t          j        fv rdt          j        v rgt          j        |           }|sOt          j                    }t$                              d
t(          j                            |                      dS dS t$                              d           dS dS )a  
        Initialize a form env, if the document has forms. If already initialized, nothing will be done.
        See the :attr:`formenv` attribute.
    
        Attention:
            If form rendering is desired, this method shall be called right after document construction, before getting document length or page handles.
        
        Parameters:
            config (FPDF_FORMFILLINFO | None):
                Custom form config interface to use (optional).
        NXFA   )version   F)r]   xfa_disabledm_pJsPlatformz*Initializing form env failed for document .zFPDF_LoadXFA() failed with zinit_forms() called on XFA pdf, but this pdfium binary was compiled without XFA support.
Run `PDFIUM_PLATFORM=auto-v8 pip install -v pypdfium2 --no-binary pypdfium2` to get a build with XFA support.)get_formtyper   FORMTYPE_NONEr   r	   flagsIPDF_JSPLATFORMFPDF_FORMFILLINFOctypespointerFPDFDOC_InitFormFillEnvironmentr
   r   _add_kidFORMTYPE_XFA_FULLFORMTYPE_XFA_FOREGROUNDFPDF_LoadXFAFPDF_GetLastErrorloggerwarningpdfium_iXFAErrorToStrget)r$   configformtypejs_platformr   okerrs          r+   
init_formszPdfDocument.init_forms   s    $$&&x----F 	?)))&6qAAA!3AEagaop{a|a|}}}!3A>>>6tVDD 	TR4RRRSSS!#tV44dl###2H4TUUU)))*400 d"466CNN#bAWA[A[\_A`A`#b#bcccccd d
 D     VUr,   c                 *    t          j        |           S )z
        Returns:
            int: PDFium form type that applies to the document (:attr:`FORMTYPE_*`).
            :attr:`FORMTYPE_NONE` if the document has no forms.
        )r   FPDF_GetFormTyper/   s    r+   rb   zPdfDocument.get_formtype   s     (...r,   c                 *    t          j        |           S )zV
        Returns:
            int: Page displaying mode (:attr:`PAGEMODE_*`).
        )r   FPDFDoc_GetPageModer/   s    r+   get_pagemodezPdfDocument.get_pagemode   s    
 +D111r,   c                 D    t          t          j        |                     S )zm
        Returns:
            bool: Whether the document is tagged (cf. PDF 1.7, 10.7 "Tagged PDF").
        )boolr   FPDFCatalog_IsTaggedr/   s    r+   	is_taggedzPdfDocument.is_tagged   s    
 X2488:::r,   r   c                    t          |t          t          f          rt          |d          d}}n-t	          j        |d          r|d}}nt          d| d          	 | t	          j        |          |f}|t          j	        | nt          j
        g ||R  }|st          d          	 |r|                                 dS dS # |r|                                 w w xY w)	a  
        Save the document at its current state.
        
        Parameters:
            dest (str | pathlib.Path | io.BytesIO):
                File path or byte stream the document shall be written to.
            version (int | None):
                The PDF version to use, given as an integer (14 for 1.4, 15 for 1.5, ...).
                If None (the default), PDFium will set a version automatically.
            flags (int):
                PDFium saving flags (defaults to 0).
        wbTwFzCannot save to ''NzFailed to save document.)r   r   r   openrq   	is_stream
ValueErrorget_bufwriterr   FPDF_SaveAsCopyFPDF_SaveWithVersionr
   r2   )r$   destr]   rd   buffer
need_closesaveargsrw   s           r+   savezPdfDocument.save   s    dS$K(( 	9!%dD!1!14JFFc** 	9!%uJFF7777888	h4V<<eDH8?)844XMjM~ltM~v}M~M~M~B >!"<===>   z s   AC Cc                     t          j        | |dd          }t          j        |          }t          j        | |||           |j        d|dz
           S )a  
        Parameters:
            type (int):
                The identifier type to retrieve (:attr:`FILEIDTYPE_*`), either permanent or changing.
                If the file was updated incrementally, the permanent identifier stays the same,
                while the changing identifier is re-calculated.
        Returns:
            bytes: Unique file identifier from the PDF's trailer dictionary.
            See PDF 1.7, Section 14.4 "File Identifiers".
        Nr   r^   )r   FPDF_GetFileIdentifierrg   create_string_bufferr   )r$   typen_bytesr   s       r+   get_identifierzPdfDocument.get_identifier   sV     1$dAFF,W55'dFGDDDz*719*%%r,   c                 h    t          j                    }t          j        | |          }|sdS |j        S )z
        Returns:
            int | None: The PDF version of the document (14 for 1.4, 15 for 1.5, ...),
            or None if the document is new or its version could not be determined.
        N)rg   c_intr   FPDF_GetFileVersionvalue)r$   r]   rw   s      r+   get_versionzPdfDocument.get_version  s6     ,..)$88 	4}r,   c                     |dz                        d          }t          j        | |dd          }t          j        |          }t          j        | |||           |j        d|dz
                               d          S )z
        Returns:
            str: Value of the given key in the PDF's metadata dictionary.
            If the key is not contained, an empty string will be returned.
         utf-8Nr   r^   	utf-16-le)encoder   FPDF_GetMetaTextrg   r   r   decode)r$   keyenc_keyr   r   s        r+   get_metadata_valuezPdfDocument.get_metadata_value  s{     <''00+D'4CC,W55!$AAAz*719*%,,[999r,   )TitleAuthorSubjectKeywordsCreatorProducerCreationDateModDatec                 n      fd j         D             }|rd |                                D             }|S )z
        Get the document's metadata as dictionary.
        
        Parameters:
            skip_empty (bool):
                If True, skip items whose value is an empty string.
        Returns:
            dict: PDF metadata.
        c                 <    i | ]}|                     |          S r.   )r   ).0kr$   s     r+   
<dictcomp>z1PdfDocument.get_metadata_dict.<locals>.<dictcomp>*  s)    NNNaAt..q11NNNr,   c                     i | ]
\  }}|||S r.   r.   )r   r   vs      r+   r   z1PdfDocument.get_metadata_dict.<locals>.<dictcomp>,  s#    ???AQ?1???r,   )METADATA_KEYSitems)r$   
skip_emptymetadatas   `  r+   get_metadata_dictzPdfDocument.get_metadata_dict   sM     ONNN4;MNNN 	@??)9)9???Hr,   c                 *    t          j        |           S )zY
        Returns:
            int: The number of embedded files in the document.
        )r   FPDFDoc_GetAttachmentCountr/   s    r+   count_attachmentszPdfDocument.count_attachments0  s    
 24888r,   c                 v    t          j        | |          }|st          d| d          t          ||           S )za
        Returns:
            PdfAttachment: The attachment at given index (zero-based).
        z"Failed to get attachment at index ra   )r   FPDFDoc_GetAttachmentr
   r   )r$   indexraw_attachments      r+   get_attachmentzPdfDocument.get_attachment8  sI    
 "7eDD 	MK5KKKLLL^T222r,   c                     |dz                        d          }t          j        |t          j                  }t          j        | |          }|st          d| d          t          ||           S )aN  
        Add a new attachment to the document. It may appear at an arbitrary index (as of PDFium 5418).
        
        Parameters:
            name (str):
                The name the attachment shall have. Usually a file name with extension.
        Returns:
            PdfAttachment: Handle to the new, empty attachment.
        r   r   z!Failed to create new attachment 'z'.)r   rg   castr   FPDF_WIDESTRINGFPDFDoc_AddAttachmentr
   r   )r$   nameenc_nameenc_name_ptrr   s        r+   new_attachmentzPdfDocument.new_attachmentC  st     6M))+66{8X-EFF!7lKK 	LJ$JJJKKK^T222r,   c                 Z    t          j        | |          }|st          d| d          dS )a  
        Unlink the attachment at given index (zero-based).
        It will be hidden from the viewer, but is still present in the file (as of PDFium 5418).
        Following attachments shift one slot to the left in the array representation used by PDFium's API.
        
        Handles to the attachment in question received from :meth:`.get_attachment`
        must not be accessed anymore after this method has been called.
        z%Failed to delete attachment at index ra   N)r   FPDFDoc_DeleteAttachmentr
   )r$   r   rw   s      r+   del_attachmentzPdfDocument.del_attachmentU  sE     .tU;; 	PNeNNNOOO	P 	Pr,   c                     t          j        | |          }|st          d          t          || | j                  }| j        r5t          j        || j                   | j                            |           n|                     |           |S )a  
        Returns:
            PdfPage: The page at given index (zero-based).
        Note:
            This calls ``FORM_OnAfterLoadPage()`` if the document has an active form env.
            In that case, note that closing the formenv would implicitly close the page.
        zFailed to load page.)r   FPDF_LoadPager
   r   r   FORM_OnAfterLoadPagerj   )r$   r   raw_pagepages       r+   rP   zPdfDocument.get_pagec  s     )$66 	64555xt|44< 	 )$===L!!$''''MM$r,   c                     |t          |           }t          j        | |||          }t          || d          }|                     |           |S )a  
        Insert a new, empty page into the document.
        
        Parameters:
            width (float):
                Target page width (horizontal size).
            height (float):
                Target page height (vertical size).
            index (int | None):
                Suggested zero-based index at which the page shall be inserted.
                If None or larger that the document's current last index, the page will be appended to the end.
        Returns:
            PdfPage: The newly created page.
        N)rK   r   FPDFPage_Newr   rj   )r$   widthheightr   r   r   s         r+   new_pagezPdfDocument.new_pagez  sR     =IIE(ueVDDxt,,dr,   c                 0    t          j        | |           dS )z
        Remove the page at given index (zero-based).
        It is recommended to close any open handles to the page before calling this method.
        N)r   FPDFPage_Delete)r$   r   s     r+   rS   zPdfDocument.del_page  s     	 u-----r,   c                 F   |t          |           }t          |t                    r+t          j        | ||                    d          |          }n>d}d}|r t          |          }t          j        |z  | }t          j        | ||||          }|st          d          dS )a.  
        Import pages from a foreign document.
        
        Parameters:
            pdf (PdfDocument):
                The document from which to import pages.
            pages (list[int] | str | None):
                The pages to include. It may either be a list of zero-based page indices, or a string of one-based page numbers and ranges.
                If None, all pages will be included.
            index (int):
                Zero-based index at which to insert the given pages. If None, they are appended to the end of the document.
        Nasciir   zFailed to import pages.)
rK   r   r   r   FPDF_ImportPagesr   rg   r   FPDF_ImportPagesByIndexr
   )r$   pdfpagesr   rw   
page_countc_pagess          r+   import_pageszPdfDocument.import_pages  s     =IIEeS!! 	Y*4ell76K6KUSSBBJG > ZZ
!<*4u=1$WjRWXXB 	97888	9 	9r,   c                     t          j                    }t          j        | ||          }|st          d          |j        |j        fS )z
        Returns:
            (float, float): Width and height of the page at given index (zero-based), in PDF canvas units.
        z!Failed to get page size by index.)r   FS_SIZEFFPDF_GetPageSizeByIndexFr
   r   r   )r$   r   sizerw   s       r+   get_page_sizezPdfDocument.get_page_size  sM    
  "".tUDAA 	CABBB
DK((r,   c                     t          j        | |dd          }t          j        |          }t          j        | |||           |j        d|dz
                               d          S )z
        Returns:
            str: Label of the page at given index (zero-based).
            (A page label is essentially an alias that may be displayed instead of the page number.)
        Nr   r^   r   )r   FPDF_GetPageLabelrg   r   r   r   )r$   r   r   r   s       r+   get_page_labelzPdfDocument.get_page_label  sd     ,T5$BB,W55"4@@@z*719*%,,[999r,   c                     t          j        || |          }|st          d| d          t          ||          }|                     |           |S )a_  
        Capture a page as XObject and attach it to a document's resources.
        
        Parameters:
            index (int):
                Zero-based index of the page.
            dest_pdf (PdfDocument):
                Target document to which the XObject shall be added.
        Returns:
            PdfXObject: The page as XObject.
        z Failed to capture page at index z as FPDF_XOBJECT.r   r   )r   FPDF_NewXObjectFromPager
   r   rj   )r$   r   dest_pdfraw_xobjectxobjects        r+   page_as_xobjectzPdfDocument.page_as_xobject  sd     6xuMM 	[YYYYZZZ(;;;gr,      c              #   
  K   |t                      }t          j        | |          }|rt          j        |j                  }||v rt                              d           dS |                    |           t          || |          V  ||dz
  k     r#| 
                    |||dz   |          E d{V  n3t          j        | |          rt                              d| d           t          j        | |          }|dS dS )z
        Iterate through the bookmarks in the document's table of contents (TOC).
        
        Parameters:
            max_depth (int):
                Maximum recursion depth to consider.
        Yields:
            :class:`.PdfBookmark`
        NzRA circular bookmark reference was detected while traversing the table of contents.   )	max_depthr?   levelseenzMaximum recursion depth z reached (subtree skipped).)setr   FPDFBookmark_GetFirstChildrg   	addressofcontentsro   rp   addr   get_tocFPDFBookmark_GetNextSibling)r$   r   r?   r   r   bm_ptraddresss          r+   r   zPdfDocument.get_toc  s?     " <55D4T6BB  	H&v77G$sttt!!!fdE22222y{""<<)FRWXYRY`d<eeeeeeeeee4T6BB b`)```aaa9$GGF!  	H 	H 	H 	H 	Hr,   )NFr   )Nr   )F)NN)r   Nr   N)+__name__
__module____qualname____doc__r"   r0   r4   r<   propertyr?   staticmethodr#   rH   rN   rQ   rT   classmethodrY   ry   rb   r~   r   r   r   FILEIDTYPE_PERMANENTr   r   r   r   r   r   r   r   r   rP   r   rS   r   r   r   r   r   __classcell__r*   s   @r+   r   r      s        @X X X X X X:    	< 	< 	< 	< 	<   X   \0 0 0            [) ) ) )X/ / /2 2 2; ; ;   > #+"? & & & &"
 
 

: 
: 
: qM    9 9 93 3 33 3 3$P P P  .   0. . .9 9 9 9>	) 	) 	)	: 	: 	:  , 'H 'H 'H 'H 'H 'H 'H 'Hr,   r   c                    d\  }}||dz                        d          }t          | t                    r9t          j        t          |           dz                        d          |          }nt          | t          t          j        f          r't          j	        | t          |           |          }| f}nlt          j        | d          r2t          j        |           \  }}|r| f}t          j        ||          }n%t          dt!          |           j         d          t          j        |          dk     rEt          j                    }t)          dt          j                            |           d	|
          |||fS )N)r.   r.   r   r   rzInvalid input type 'r   r   z!Failed to load document (PDFium: z).)err_code)r   r   r   r   FPDF_LoadDocumentr   r9   rg   ArrayFPDF_LoadMemDocument64rK   rq   r   get_bufreaderFPDF_LoadCustomDocument	TypeErrorr   r  rG   rn   r
   
ErrorToStrrs   )
input_datar&   r'   r(   r)   r   	bufaccessr  s           r+   r    r      s}   GXVO++G44*d## M(#j//&*@)H)H)Q)QS[\\	J 5	6	6 	M-j#j//8TT.		J	,	, M%3J??	7 	&"~H.y(CCKtJ/?/?/HKKKLLL!#&&**-//ch>Q>U>UV^>_>_cccnvwwww!!r,   c                   N     e Zd ZdZ fdZed             Zed             Z xZ	S )r   aM  
    Form environment helper class.
    
    Attributes:
        raw (FPDF_FORMHANDLE):
            The underlying PDFium form env handle.
        config (FPDF_FORMFILLINFO):
            Accompanying form configuration interface, to be kept alive.
        pdf (PdfDocument):
            Parent document this form env belongs to.
    c                     || _         || _        || _        t                                          t
          j        | j        | j                   d S r   )r   r   rt   r!   r"   r   r#   )r$   r   r   rt   r*   s       r+   r"   zPdfFormEnv.__init__7  sA    /dhGGGGGr,   c                     | j         S r   r   r/   s    r+   r?   zPdfFormEnv.parent=  	    xr,   c                 Z    t          j        |            t          |           d |_        d S r   )r   FPDFDOC_ExitFormFillEnvironmentr;   r   )r   rt   r   s      r+   r#   zPdfFormEnv._close_implA  s)    0555
6


r,   )
r  r  r  r  r"   r  r?   r  r#   r	  r
  s   @r+   r   r   *  s}        
 
H H H H H   X   \    r,   r   c                   >     e Zd ZdZ fdZed             Zd Z xZS )r   z
    XObject helper class.
    
    Attributes:
        raw (FPDF_XOBJECT): The underlying PDFium XObject handle.
        pdf (PdfDocument): Reference to the document this XObject belongs to.
    c                 z    || _         || _        t                                          t          j                   d S r   )r   r   r!   r"   r   FPDF_CloseXObject)r$   r   r   r*   s      r+   r"   zPdfXObject.__init__Q  s2    344444r,   c                     | j         S r   r  r/   s    r+   r?   zPdfXObject.parentV  r  r,   c                 V    t          j        |           }t          || j                  S )a  
        Returns:
            PdfObject: An independent pageobject representation of the XObject.
            If multiple pageobjects are created from an XObject, they share resources.
            Returned pageobjects remain valid after the XObject is closed.
        r   )r   FPDF_NewFormObjectFromXObjectr   r   )r$   raw_pageobjs     r+   as_pageobjectzPdfXObject.as_pageobjectZ  s)     <TBB[dh7777r,   )	r  r  r  r  r"   r  r?   r%  r	  r
  s   @r+   r   r   H  sl         5 5 5 5 5
   X	8 	8 	8 	8 	8 	8 	8r,   r   c                   *    e Zd ZdZd Zd Zd Zd ZdS )r   ak  
    Bookmark helper class.
    
    Attributes:
        raw (FPDF_BOOKMARK):
            The underlying PDFium bookmark handle.
        pdf (PdfDocument):
            Reference to the document this bookmark belongs to.
        level (int):
            The bookmark's nesting level in the TOC tree (zero-based). Corresponds to the number of parent bookmarks.
    c                 0    || _         || _        || _        d S r   )r   r   r   )r$   r   r   r   s       r+   r"   zPdfBookmark.__init__s  s    


r,   c                     t          j        | dd          }t          j        |          }t          j        | ||           |j        d|dz
                               d          S )zH
        Returns:
            str: The bookmark's title string.
        Nr   r^   r   )r   FPDFBookmark_GetTitlerg   r   r   r   )r$   r   r   s      r+   	get_titlezPdfBookmark.get_titlex  s`    
 0tQ??,W55&tVW===z*719*%,,[999r,   c                 *    t          j        |           S )a_  
        Returns:
            int: Signed number of child bookmarks that would be visible if the bookmark were open (i.e. recursively counting children of open children).
            The bookmark's initial state is open (expanded) if the number is positive, closed (collapsed) if negative.
            Zero if the bookmark has no descendants.
        )r   FPDFBookmark_GetCountr/   s    r+   	get_countzPdfBookmark.get_count  s     -d333r,   c                 j    t          j        | j        |           }|sdS t          || j                  S )z
        Returns:
            PdfDest | None: The bookmark's destination (an object providing page index and viewport), or None on failure.
        Nr  )r   FPDFBookmark_GetDestr   r   )r$   raw_dests     r+   get_destzPdfBookmark.get_dest  s:    
 04@@ 	4xTX....r,   N)r  r  r  r  r"   r*  r-  r1  r.   r,   r+   r   r   f  sZ        
 
  
: : :4 4 4/ / / / /r,   r   c                   $    e Zd ZdZd Zd Zd ZdS )r   z
    Destination helper class.
    
    Attributes:
        raw (FPDF_DEST): The underlying PDFium destination handle.
        pdf (PdfDocument): Reference to the document this dest belongs to.
    c                 "    || _         || _        d S r   r   )r$   r   r   s      r+   r"   zPdfDest.__init__  s    r,   c                 J    t          j        | j        |           }|dk    r|ndS )zw
        Returns:
            int | None: Zero-based index of the page the dest points to, or None on failure.
        r   N)r   FPDFDest_GetDestPageIndexr   )r$   vals     r+   	get_indexzPdfDest.get_index  s*    
 04@@QhhssD(r,   c                     t          j                    }t          j        dz              }t          j        | ||          }t          |          d|j                 }||fS )aw  
        Returns:
            (int, list[float]): A tuple of (view_mode, view_pos).
            *view_mode* is a constant (one of :data:`PDFDEST_VIEW_*`) defining how *view_pos* shall be interpreted.
            *view_pos* is the target position on the page the dest points to.
            It may contain between 0 to 4 float coordinates, depending on the view mode.
           N)rg   c_ulongr   FS_FLOATFPDFDest_GetViewlistr   )r$   n_paramsposmodes       r+   get_viewzPdfDest.get_view  sX     >## 1$''(x==3ii(Syr,   N)r  r  r  r  r"   r7  rA  r.   r,   r+   r   r     sK           ) ) )    r,   r   ) __all__rg   loggingpathlibr   pypdfium2.rawr   r   pypdfium2.internalinternalrq   pypdfium2.versionr	   pypdfium2._helpers.miscr
   pypdfium2._helpers.pager   pypdfium2._helpers.pageobjectsr   pypdfium2._helpers.attachmentr   	getLoggerr  ro   AutoCloseabler   r    r   r   AutoCastabler   r   r.   r,   r+   <module>rP     s   P                     % % % % % % ) ) ) ) ) ) / / / / / / + + + + + + 4 4 4 4 4 4 7 7 7 7 7 7		8	$	$xH xH xH xH xH8) xH xH xHv" " "4    ((   <8 8 8 8 8(( 8 8 8<-/ -/ -/ -/ -/8( -/ -/ -/`! ! ! ! !x$ ! ! ! ! !r,   