
    ,h w                     ~   d dl Z d dlmZmZmZ d dlmZ d dlmZ d dl	m
Z
mZmZmZmZmZmZmZmZ ddlmZ ddlmZ dd	lmZ dd
lmZmZmZmZ ddlmZ ddl m!Z! ddl m"Z# ddl m$Z$m%Z% ddl&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3 ddl4m5Z5m6Z6 ddlm7Z7m8Z8m9Z9m:Z:m;Z; dZ< G d d      Z= G d d      Z> G d de>      Z?y)    N)BytesIOFileIOIOBase)Path)TracebackType)	AnyDictIterableListOptionalTupleTypeUnioncast   )
Encryption)
PageObject)	PdfReader)StrByteTypedeprecation_bookmarkdeprecation_with_replacementstr_)	PdfWriter)GoToActionArguments)PagesAttributes)TypArgumentsTypFitArguments)PAGE_FITArrayObjectDestinationDictionaryObjectFitFloatObjectIndirectObject
NameObject
NullObjectNumberObjectOutlineItemTextStringObject
TreeObject)	PageRangePageRangeSpec)FitType
LayoutTypeOutlineTypePagemodeTypeZoomArgTypez=close() was called and thus the writer cannot be used anymorec                   (    e Zd ZdZdedededdfdZy)_MergedPagez@Collect necessary information on each page that is being merged.pagedatasrcidreturnNc                 <    || _         || _        d | _        || _        y N)r5   r4   out_pagedatar6   )selfr4   r5   r6   s       P/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/PyPDF2/_merger.py__init__z_MergedPage.__init__Q   s          )__name__
__module____qualname____doc__r   r   intr=    r>   r<   r3   r3   N   s&    J )   r>   r3   c                      e Zd ZdZ ed      	 d>dedeeef   ddfd	       Z	d?d
Z
deee      dee   dee   ddfdZ edd      	 	 	 	 	 	 d@dee   deeeef   dee   dee   dedee   ddfd       Zdeeeef   deeee   f   fdZ edd      	 	 	 dAdeeeef   dee   dedeeeef   eeeef   ee   f   deddf
d       Zdeeef   ddfdZdBdZdeeef   ddfdZ deeef   ddfdZ!de"ddfdZ#de"ddfdZ$d e%ddfd!Z&d e%ddfd"Z'd#ed$eeeeef   f   deeeef   eeeef   ee   f   deeeef      fd%Z(d#ede)deeeef   eeeef   ee   f   de)fd&Z*dBd'Z+ ed      	 	 dCdee,e-      d(ee.   ddfd)       Z/ ed*      dee-e0f   d+e1ddfd,       Z2dee1   ddfd-Z3 ed      	 dDdee1   dee,e-      ddfd.       Z4 ed*      	 dDdeeef   d/ee)   deee      fd0       Z5 ed*      	 dDdeeef   d/ee)   deee      fd1       Z6ddddde7dfd2edee   d(ede.e8f   d3eee9e9e9f      d4ed5ed6e:d7ee   de8fd8Z;	 	 	 	 	 dEd2ed7ed(ede.e8f   d3eee9e9e9f      d4ed5ed6e<d9e=de8fd:Z>	 	 	 	 	 dEd2ed7ed(ede.e8f   d3eee9e9e9f      d4ed5ed6e<d9e=de8fd;Z?d2ed7eddfd<Z@	 	 dCd2edee   d7ee   ddfd=ZAy)F	PdfMergeraI  
    Initialize a ``PdfMerger`` object.

    ``PdfMerger`` merges multiple PDFs into a single PDF.
    It can concatenate, slice, insert, or any combination of the above.

    See the functions :meth:`merge()<merge>` (or :meth:`append()<append>`)
    and :meth:`write()<write>` for usage information.

    :param bool strict: Determines whether user should be warned of all
            problems and also causes some correctable problems to be fatal.
            Defaults to ``False``.
    :param fileobj: Output file. Can be a filename or any kind of
            file-like object.
    outline)	bookmarksFstrictfileobjr7   Nc                     g | _         g | _        t               | _        g | _        g | _        d| _        || _        || _        y )Nr   )	inputspagesr   outputrG   named_destsid_countrJ   rI   )r;   rI   rJ   s      r<   r=   zPdfMerger.__init__i   s?     46 "
+4;$&&(r>   c                     | S r9   rD   )r;   s    r<   	__enter__zPdfMerger.__enter__v   s    r>   exc_typeexc	tracebackc                 r    | j                   r| j                  | j                          | j                          y)z*Write to the fileobj and close the merger.N)rJ   writeclose)r;   rS   rT   rU   s       r<   __exit__zPdfMerger.__exit__z   s$     <<JJt||$

r>   outline_itemimport_outline)bookmarkimport_bookmarkspage_numberrM   positionc                    |4|'|}d}d}t        j                  | d| dt               nt        d      |t        d      |t        d      | j	                  |      \  }	}
t        |	| j                  	      }| j                  j                  |	|f       |
|
|_	        |d
t        |j                        f}nat        |t              r%|j                  t        |j                              }n,t        |t              rnt        |t               st#        d      g }g }|r|j$                  }| j'                  |||      }|rSt)        t+        |      t-        | j.                        t1        j2                               }| xj$                  ||gz  c_        n| xj$                  |z  c_        |j4                  }| j7                  |||      }| xj8                  |z  c_        t;        | D ]P  }|j                  |   }| j.                  }| xj.                  dz  c_        t=        |||      }|j                  |       R | j?                  |       | jA                  |       || j                  || y)a  
        Merge the pages from the given file into the output file at the
        specified page number.

        :param int page_number: The *page number* to insert this file. File will
            be inserted after the given number.

        :param fileobj: A File Object or an object that supports the standard
            read and seek methods similar to a File Object. Could also be a
            string representing a path to a PDF file.

        :param str outline_item: Optionally, you may specify an outline item
            (previously referred to as a 'bookmark') to be applied at the
            beginning of the included file by supplying the text of the outline item.

        :param pages: can be a :class:`PageRange<PyPDF2.pagerange.PageRange>`
            or a ``(start, stop[, step])`` tuple
            to merge only the specified range of pages from the source
            document into the output document.
            Can also be a list of pages to merge.

        :param bool import_outline: You may prevent the source document's
            outline (collection of outline items, previously referred to as
            'bookmarks') from being imported by specifying this as ``False``.
        Nr_   r^   zG is deprecated as an argument and will be removed in PyPDF2=4.0.0. Use  insteadzCThe argument position of merge is deprecated. Use page_number only.page_number may not be Nonezfileobj may not be None)rI   r   z0"pages" must be a tuple of (start, stop[, step])r   )!warningswarnDeprecationWarning
ValueError_create_streamr   rI   rL   append_encryptionlenrM   
isinstancer+   indiceslisttuple	TypeErrorrG   _trim_outliner(   r)   r'   rP   r"   fitnamed_destinations_trim_destsrO   ranger3   _associate_dests_to_pages!_associate_outline_items_to_pages)r;   r^   rJ   rZ   rM   r[   r_   old_termnew_termstreamencryption_objreadersrcpagesrG   outline_item_typdeststrimmed_destsipager6   mps                        r<   mergezPdfMerger.merge   sY   F "&%(#* %88@zK ' !Y   :;;? 677!%!4!4W!= 6$++6FF+,%!/F =FLL)*Ey)MM#fll"34Et$E5)NOOnnG((%@G* .T]]+	 
 LL-w77LLLG#L))((>M)  	 A<<?DBMMQMT62.BOOB	  	&&x0..x8 /7

;{+r>   c                 6   d }t        |t        t        f      rt        |d      }||fS t        |t              r|j
                  r|j
                  }|j                  j                         }|j                  j                  d       t        |j                  j                               }|j                  j                  |       ||fS t        |d      r<t        |d      r0|j                  d       |j                         }t        |      }||fS t        d      )Nrbr   seekreadzPdfMerger.merge requires an object that PdfReader can parse. Typically, that is a Path or a string representing a Path, a file object, or an object implementing .seek and .read. Passing a PdfReader directly works as well.)rk   strr   r   r   ri   ry   tellr   r   r   hasattrNotImplementedError)r;   rJ   rz   ry   	orig_tellfilecontents         r<   rg   zPdfMerger._create_stream   s    gT{+GT*F* ~%%) +""!(!4!4++-INN"W^^0023F NN	* ~%% Wf%''6*BLLO!,,.K[)F ~%% &> r>   c                 T    | j                  t        | j                        ||||       y)a  
        Identical to the :meth:`merge()<merge>` method, but assumes you want to
        concatenate all pages onto the end of the file instead of specifying a
        position.

        :param fileobj: A File Object or an object that supports the standard
            read and seek methods similar to a File Object. Could also be a
            string representing a path to a PDF file.

        :param str outline_item: Optionally, you may specify an outline item
            (previously referred to as a 'bookmark') to be applied at the
            beginning of the included file by supplying the text of the outline item.

        :param pages: can be a :class:`PageRange<PyPDF2.pagerange.PageRange>`
            or a ``(start, stop[, step])`` tuple
            to merge only the specified range of pages from the source
            document into the output document.
            Can also be a list of pages to append.

        :param bool import_outline: You may prevent the source document's
            outline (collection of outline items, previously referred to as
            'bookmarks') from being imported by specifying this as ``False``.
        N)r   rj   rM   )r;   rJ   rZ   rM   r[   s        r<   rh   zPdfMerger.append  s!    B 	

3tzz?G\5.Qr>   c                 J   | j                   t        t              | j                  D ]  }| j                   j	                  |j
                         t        t        t        t        f   | j                   j                  j                               }| j                   j                  |t        j                     d   j                               |_         | j!                          | j#                          | j                   j%                  |      \  }}|r|j'                          yy)z
        Write all data that has been merged to the given output file.

        :param fileobj: Output file. Can be a filename or any kind of
            file-like object.
        N)rN   RuntimeErrorERR_CLOSED_WRITERrM   add_pager4   r   r	   r   r   _pages
get_objectget_referencePAKIDSr:   _write_dests_write_outlinerW   rX   )r;   rJ   r   	pages_objmy_fileret_fileobjs         r<   rW   zPdfMerger.writeA  s     ;;011
 JJ 	DKK  /T#s(^T[[-?-?-J-J-LMI $ 9 9"''"2&113!D	 	  ${{009 r>   c                 v    g | _         | j                  D ]  \  }}|j                           g | _        d| _        y)zHShut all file descriptors (input and output) and clear all memory usage.N)rM   rL   rX   rN   )r;   fo_readers      r<   rX   zPdfMerger.closea  s9    
;; 	KBHHJ	 r>   infosc                 p    | j                   t        t              | j                   j                  |       y)z
        Add custom metadata to the output.

        :param dict infos: a Python dictionary where each key is a field
            and each value is your new metadata.
            Example: ``{u'/Title': u'My title'}``
        N)rN   r   r   add_metadatar;   r   s     r<   r   zPdfMerger.add_metadataj  s,     ;;011  'r>   c                 >    t        dd       | j                  |       y)zW
        .. deprecated:: 1.28.0

            Use :meth:`add_metadata` instead.
        addMetadatar   N)r   r   r   s     r<   r   zPdfMerger.addMetadatav  s     	%]NC% r>   layoutc                 >    t        dd       | j                  |       y)zZ
        .. deprecated:: 1.28.0

            Use :meth:`set_page_layout` instead.
        setPageLayoutset_page_layoutN)r   r   r;   r   s     r<   r   zPdfMerger.setPageLayout  s     	%_6GHV$r>   c                 p    | j                   t        t              | j                   j                  |       y)a  
        Set the page layout.

        :param str layout: The page layout to be used

        .. list-table:: Valid ``layout`` arguments
           :widths: 50 200

           * - /NoLayout
             - Layout explicitly not specified
           * - /SinglePage
             - Show one page at a time
           * - /OneColumn
             - Show one column at a time
           * - /TwoColumnLeft
             - Show pages in two columns, odd-numbered pages on the left
           * - /TwoColumnRight
             - Show pages in two columns, odd-numbered pages on the right
           * - /TwoPageLeft
             - Show two pages at a time, odd-numbered pages on the left
           * - /TwoPageRight
             - Show two pages at a time, odd-numbered pages on the right
        N)rN   r   r   _set_page_layoutr   s     r<   r   zPdfMerger.set_page_layout  s,    0 ;;011$$V,r>   modec                 @    t        ddd       | j                  |       y)zX
        .. deprecated:: 1.28.0

            Use :meth:`set_page_mode` instead.
        setPageModeset_page_mode3.0.0N)r   r   r;   r   s     r<   r   zPdfMerger.setPageMode  s     	%]OWM4 r>   c                 p    | j                   t        t              | j                   j                  |       y)aP  
        Set the page mode.

        :param str mode: The page mode to use.

        .. list-table:: Valid ``mode`` arguments
           :widths: 50 200

           * - /UseNone
             - Do not show outline or thumbnails panels
           * - /UseOutlines
             - Show outline (aka bookmarks) panel
           * - /UseThumbs
             - Show page thumbnails panel
           * - /FullScreen
             - Fullscreen view
           * - /UseOC
             - Show Optional Content Group (OCG) panel
           * - /UseAttachments
             - Show attachments panel
        N)rN   r   r   r   r   s     r<   r   zPdfMerger.set_page_mode  s,    , ;;011!!$'r>   pdfr~   c                    g }t        |t              r|nt        t        |       }|j                         D ]  \  }}|D ]  }|j                  |   j                         |d   j                         k(  s5|d   j                         |t        d      <   t        |      t        |d         k(  sJ |j                  |          |S )zHRemove named destinations that are not a part of the specified page set./Page/Title)	rk   rm   rt   itemsrM   r   r%   r   rh   )	r;   r   r~   rM   	new_destslstkeyobjjs	            r<   rs   zPdfMerger._trim_dests  s     	!%.eD4G 	HC 99Q<**,G0G0G0II/27|/F/F/HC
7+,9S](;;;$$S)	 r>   c                    g }d}t        |t              r|nt        t        |       }t        |      D ]  \  }}t        |t              rA| j	                  |||      }	|	s,|s|j                  ||dz
            |j                  |	       Wd}|D ]m  }
|d   	|j                  |
   j                         |d   j                         k(  s;|d   j                         |t        d      <   |j                  |       d}   |S )zJRemove outline item entries that are not a part of the specified page set.Tr   Fr   )	rk   rm   rt   	enumeraterp   rh   rM   r   r%   )r;   r   rG   rM   new_outlineprev_header_addedr   r   rZ   subr   s              r<   rp   zPdfMerger._trim_outline  s     !%.eD4G(1 	OA|,-((lC@,#**71q5>:&&s+$)! 	A#G,4 yy|..0L4I4T4T4VV<H#=$*, %Z%89 $**<8,0)		& r>   c                 6   | j                   t        t              | j                  D ]o  }d }d|v rIt	        | j
                        D ]1  \  }}|j                  |d   k(  s|j                  |t        d      <    n |U| j                   j                  |       q y )Nr   )
rN   r   r   rO   r   rM   r6   r:   r%   add_named_destination_object)r;   
named_destpagenor   s       r<   r   zPdfMerger._write_dests  s    ;;011** 		EJF*$$-djj$9 LFDww*W"55:>:K:K
:g#67
 !88D		Er>   parentc                    | j                   t        t              || j                  }|J d       d }|D ]  }t	        |t
              r| j                  ||       &d }d|v rCt        | j                        D ]+  \  }}|j                  |d   k(  s| j                  ||        n |r|d= |d= | j                   j                  ||      } y )Nhint for mypyr   /Type)rN   r   r   rG   rk   rm   r   r   rM   r6   _write_outline_item_on_pageadd_outline_item_dict)r;   rG   r   
last_addedrZ   page_nor   s          r<   r   zPdfMerger._write_outline  s     ;;011?llG"3O3
# 	UL,-##L*=G,&%.tzz%: MGTww,w"7788tL " )<+@![[>>|VT
	Ur>   )r\   r   c                    t        t        |d         }t        |j                        t	        |      g}t
        j                  t        j                  ft
        j                  t        j                  ft
        j                  t        j                  ft
        j                  t        j                  ft
        j                  t        j                  t        j                  dft
        j                  t        j                  t        j                  t        j                   t        j                  fi}|j#                  |t%                     D ]T  }||v r1t'        ||   t(              s|j+                  t-        ||                n|j+                  t-        d             ||= V t/        t	        t0        j2                        t	        d      t	        t0        j4                        t7        |      i      |t	        d      <   y )Nr   z/Zoomr   z/GoToz/A)r   r   r'   r6   r%   r   FIT_Hr   TOPFIT_BHFIT_VLEFTFIT_BVXYZFIT_RBOTTOMRIGHTgetrn   rk   r&   rh   r#   r!   r   SDr   )r;   rZ   r   oi_typeargsfit2arg_keysarg_keys          r<   r   z%PdfMerger._write_outline_item_on_page"  s    sL12TWW%z'':;!!L$4$4#6""\%5%5$7!!L$5$5#7""\%6%6$8,"3"3\5E5Ew!O!!!!##""  	$4
 $''9 	&G,&zW%z0 KW(=>?KN+W%	& *:.001:g3F.001;t3D*
Z%&r>   c                 *   | j                   D ]  }d }|d   }t        |t              r|D ]:  }|j                         |j                  j                         k(  s/|j
                  }< |t        d|d    d      t        |      |t        d      <    y )Nr   zUnresolved named destination 'r   ')rO   rk   r'   r   r4   r6   rf   r%   )r;   rM   r   r   npr   s         r<   ru   z#PdfMerger._associate_dests_to_pagesE  s    ** 	CJFG$B"l+ %==?dmm&>&>&@@!WWF% ~ 4Z5I4J!L  /;6.BJz'*+	Cr>   c                 h   || j                   }|J d       |D ]  }t        |t              r| j                  ||       &d }|d   }t        |t              r>|D ]:  }|j                         |j                  j                         k(  s/|j                  }< |t	        |      |t        d      <    y )Nr   r   )	rG   rk   rm   rv   r'   r   r4   r6   r%   )r;   rM   rG   rZ   r   outline_item_pageps          r<   rv   z+PdfMerger._associate_outline_items_to_pagesW  s     ?llG"3O3# 	IL,-66ulKF ,W 5+\: "$//1QZZ5J5J5LLTTF" !4@4HZ01!	Ir>   rootc                     || j                   }t        |      D ]_  \  }}t        |t              r| j	                  ||      }|s+|g|z   c S ||k(  s$t        t        t        t        f   |d         |k(  s\|gc S  y )Nr   )rG   r   rk   rm   find_outline_itemr   r	   r   )r;   rZ   r   r   oi_enumress         r<   r   zPdfMerger.find_outline_itemp  s     <<<D#D/ 	JAw'4( ,,\7C39$<'S#X(9:lJ s
	 r>   c                 &    | j                  ||      S )zZ
        .. deprecated:: 2.9.0
            Use :meth:`find_outline_item` instead.
        )r   )r;   rZ   r   s      r<   find_bookmarkzPdfMerger.find_bookmark  s     %%lD99r>   titlecolorbolditalicrq   pagenumc	           
          ||t        d      |&d}	d}
t        j                  |	 d|
 dt               |}|t        d      | j                  }|t        t              |j                  |||d||||      S )al  
        Add an outline item (commonly referred to as a "Bookmark") to this PDF file.

        :param str title: Title to use for this outline item.
        :param int page_number: Page number this outline item will point to.
        :param parent: A reference to a parent outline item to create nested
            outline items.
        :param tuple color: Color of the outline item's font as a red, green, blue tuple
            from 0.0 to 1.0
        :param bool bold: Outline item font is bold
        :param bool italic: Outline item font is italic
        :param Fit fit: The fit of the destination page.
        NzMThe argument pagenum of add_outline_item is deprecated. Use page_number only.r   r^   H is deprecated as an argument and will be removed in PyPDF2==4.0.0. Use ra   rb   )rf   rc   rd   re   rN   r   r   add_outline_item)r;   r   r^   r   r   r   r   rq   r   rw   rx   writers               r<   r   zPdfMerger.add_outline_item  s    0 "w':_   H$HMMj !55=JhH # "K:;;>011&&	
 		
r>   r   c                 `    t        ddd       | j                  ||||||t        ||            S )zZ
        .. deprecated:: 1.28.0
            Use :meth:`add_outline_item` instead.
        addBookmarkr   r   fit_typefit_argsr   r   r"   	r;   r   r   r   r   r   r   rq   r   s	            r<   r   zPdfMerger.addBookmark  @     	%]4FP$$t,
 	
r>   c                 `    t        ddd       | j                  ||||||t        ||            S )zY
        .. deprecated:: 2.9.0
            Use :meth:`add_outline_item` instead.
        r   r   r   r   r   r   s	            r<   add_bookmarkzPdfMerger.add_bookmark  r   r>   c                 @    t        ddd       | j                  ||      S )z_
        .. deprecated:: 1.28.0
            Use :meth:`add_named_destination` instead.
        addNamedDestinationadd_named_destinationr   )r   r  )r;   r   r   s      r<   r  zPdfMerger.addNamedDestination   s)    
 	%!#:G	
 ))%99r>   c                 (   ||t        d      |&d}d}t        j                  | d| dt               |}|t        d      t	        t        |      t        |      t        j                  d	            }| j                  j                  |       y)
z
        Add a destination to the output.

        :param str title: Title to use
        :param int page_number: Page number this destination points at.
        NzRThe argument pagenum of add_named_destination is deprecated. Use page_number only.r   r^   r   ra   rb   i:  )top)rf   rc   rd   re   r    r)   r'   r"   fit_horizontallyrO   rh   )r;   r   r^   r   rw   rx   dests          r<   r  zPdfMerger.add_named_destination
  s     "w':d   H$HMMj !55=JhH # "K:;;U#%  S)

 	%r>   )F )r7   rF   )NNNNTN)NNT)r7   N)NNr9   )NNFFz/Fit)Br?   r@   rA   rB   r   boolr   r   r   r=   rR   r   r   BaseExceptionr   rY   rC   r   r   r,   r   r   r   r   rg   r+   r   rh   rW   rX   r	   r   r   r   r.   r   r   r0   r   r   rs   r/   rp   r   r
   r(   r*   r   r    r3   r   ru   rv   r   r   r   r$   floatr"   r   r-   r1   r   r  r  r  rD   r>   r<   rF   rF   X   s     I.HJ

-243D-E
	
 /
	4./	 m$	 M*		
 
	 >DTU &*7;&*)-#"&s7c]s7 t[)34s7 sm	s7
 &s7 s7 3-s7 
s7 Vs7j!&T;	9:!&	vx
++	,!&F >DTU '+ # R{It34 R sm R )U38_eCcM.BDIM
	 R  R 
 R V RD U4#45  $  @
($sCx. 
(T 
(!c3h !D !%J %4 %-j -T -8! ! !(, (4 (4 Cc3h'( U38_eCcM&:DIEF	
 
d38n	$  U38_eCcM&:DIEF	
 
>E I. 48'+U(;/0U $U 
	U /U6 >2 
!+{":; 
CN 
	 
 3 
DCtK/@ CT C$ I.SWI+&I19(;:O1PI	I /I0 >2 '+38n {# 
$s)		 30 >2 '+	:38n	: {#	: 
$s)			: 3	: &*:>6:!%5
5
 c]5
 dJ67	5

 eUE1235
 5
 5
 5
 #5
 
5
v ;?6:

 
 dJ67	

 eUE123
 
 
 
 
 

< ;?6:

 
 dJ67	

 eUE123
 
 
 
 
 

4: :s :t : &*!%	"&"& c]"& #	"&
 
"&r>   rF   c                   ,     e Zd Zdededdf fdZ xZS )PdfFileMergerr   kwargsr7   Nc                 l    t        ddd       d|vrt        |      dk  rd|d<   t        |   |i | y )Nr  rF   r   rI   r   T)r   rj   superr=   )r;   r   r  	__class__s      r<   r=   zPdfFileMerger.__init__0  s=    $_k7K6!c$i!m#F8$)&)r>   )r?   r@   rA   r   r=   __classcell__)r  s   @r<   r  r  /  s"    *c *S *T * *r>   r  )@rc   ior   r   r   pathlibr   typesr   typingr   r	   r
   r   r   r   r   r   r   ri   r   _pager   r   r   _utilsr   r   r   r   _writerr   	constantsr   r   r   r   r   genericr   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   	pageranger+   r,   r-   r.   r/   r0   r1   r   r3   rF   r  rD   r>   r<   <module>r     s   8  & &  
 
 
 $     * , 4    0 N NS  T& T&n*I *r>   