a
    ¢…¢f7  ã                   @   sì  d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl	Z	d dl
m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mZmZm Z m!Z! ddl"m#Z# dd	l$m%Z%m&Z& dd
l'm(Z( ddl)m*Z*m+Z+m,Z, ddl-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5 ddl6m7Z7 ddl6m8Z9 ddl6m:Z: ddl6m;Z< ddl6m=Z> ddl6m?Z?m@Z@mAZAmBZBmCZC ddl6mDZE ddl6mFZG ddl6mHZI ddl6mJZK ddl6mLZLmMZM ddlNmOZOmPZPmQZQmRZRmSZSmTZTmUZUmVZVmWZWmXZXmYZYmZZZm[Z[m\Z\m]Z]m^Z^m_Z_m`Z`maZambZbmcZcmdZd ddlemfZfmgZg ddlmhZhmiZimjZjmkZkmlZlmmZmmnZn e oep¡Zqe@d ƒZreMdƒZsG dd„ dƒZte eeuef euevee f e^dœdd „Zwe deZf eue eexexexf eudf eyeyebd!œd"d#„ZzG d$d%„ d%etƒZ{dS )&é    N)Úmd5)ÚBytesIOÚFileIOÚIOBase)ÚPath)ÚTracebackType)ÚIOÚAnyÚCallableÚDequeÚDictÚIterableÚListÚOptionalÚPatternÚTupleÚTypeÚUnionÚcasté   )Ú
Encryption)Ú
PageObjectÚ_VirtualList)Ú	PdfReader)Ú_alg33Ú_alg34Ú_alg35)ÚStrByteTypeÚ
StreamTypeÚ_get_max_pdf_version_headerÚb_Údeprecate_with_replacementÚdeprecation_bookmarkÚdeprecation_with_replacementÚlogger_warning)ÚAnnotationDictionaryAttributes)ÚCatalogAttributes)ÚCatalogDictionary)ÚCore)ÚEncryptionDictAttributes)ÚFieldDictionaryAttributesÚ	FieldFlagÚ"FileSpecificationDictionaryEntriesÚGoToActionArgumentsÚInteractiveFormDictEntries)ÚPageAttributes)ÚPagesAttributes)ÚStreamAttributes)ÚTrailerKeys)ÚTypFitArgumentsÚUserAccessPermissions)ÚPAGE_FITÚAnnotationBuilderÚArrayObjectÚBooleanObjectÚByteStringObjectÚContentStreamÚDecodedStreamObjectÚDestinationÚDictionaryObjectÚFitÚFloatObjectÚIndirectObjectÚ
NameObjectÚ
NullObjectÚNumberObjectÚ	PdfObjectÚRectangleObjectÚStreamObjectÚTextStringObjectÚ
TreeObjectÚcreate_string_objectÚ
hex_to_rgb)Ú	PageRangeÚPageRangeSpec)ÚBorderArrayTypeÚFitTypeÚ
LayoutTypeÚOutlineItemTypeÚOutlineTypeÚPagemodeTypeÚZoomArgTypeiüÿÿc                   @   s  e Zd ZdZ�d#eddœdd„Zd dœdd	„Zeee	  ee	 ee
 dd
œdd„Zeedœdd„ƒZejeddœdd„ƒZeedœdd„Z�d$edeef ee edœdd„Zeeef edœdd„Z�d%eeeegdf ee edœdd„Zddœdd„Z�d&eee ed œd!d"„Z�d'eee ed œd#d$„Z�d(eeee ed&œd'd(„Z �d)eeee ed&œd)d*„Z!�d*ee ee ed+œd,d-„Z"eed.œd/d0„Z#edœd1d2„Z$edœd3d4„Z%ee&e dœd5d6„ƒZ'�d+ee( ee( ed7œd8d9„Z)�d,ee( ee( ed7œd:d;„Z*�d-ee+j, ee+j, eed<œd=d>„Z-�d.ee+j, ee+j, eed<œd?d@„Z.eede/e0e1f dœdAdB„ƒZ2e2jedee/ef ddCœdDdB„ƒZ2eddEœdFdG„Z3eddEœdHdI„Z4eeeef ddJœdKdL„Z5eeeef ddMœdNdO„Z6�d/e7eeegdf  ddPœdQdR„Z8�d0e7eeegdf  ddPœdSdT„Z9e:fee;eef e<ddUœdVdW„Z=e:fee;eef e<ddUœdXdY„Z>e7ddZœd[d\„Z?e7ddZœd]d^„Z@�d1e7eeegdf  ddPœd_d`„ZA�d2e7eeegdf  ddPœdadb„ZBdddceCddfee ee eDeEee ee dddœdedf„ZFeGddgœdhdi„ZHeeIef eJeDeKf dgœdjdk„ZLeGe&e dgœdldm„ZMeGe&e ednœdodp„ZNeGddgœdqdr„ZOe;eef ddsœdtdu„ZPe;eef ddsœdvdw„ZQeeReSeTeUeeVeeWe0eXf
 ddxœdydz„ZYeed{œd|d}„ZZeedœd~d„Z[eedœd€d�„Z\e]dœd‚dƒ„Z^eRdœd„d…„Z_eeRdœd†d‡„ƒZ`e]dœdˆd‰„ZaeRdœdŠd‹„ZbeRdœdŒd�„Zc�d3edee]f ede]ef ede]ef edee]f edŽœd�d�„Zd�d4eee]f ede]ef ed‘œd’d“„Ze�d5eee] ed‘œd”d•„Zfegd–d—��d6ehede]ef ede]ef ed˜œd™dš„ƒZiegd–d—��d7ehee] ed›œdœd�„ƒZjegd–d—��d8ehee] ed›œdždŸ„ƒZkdddd d eldfeedeeef ede]ef ede]ef eeeJe(e(e(f ef  eDeDemee ed¡œ
d¢d£„Zn�d9eeede]ef eeJe(e(e(f  eDeDeoeped¥œ	d¦d§„Zq�d:eeede]ef eeJe(e(e(f  eDeDeoeped¥œ	d¨d©„Zrddœdªd«„Zse0eeeRf dd¬œd­d®„Zt�d;ee ee ed¯œd°d±„Zue/edCœd²d³„Zv�d<eee ee ed´œdµd¶„Zweeed·œd¸d¹„Zxddœdºd»„Zyddœd¼d½„Zz�d=eDdd¾œd¿dÀ„Z{�d>eDddÁœdÂdÃ„Z|�d?eDdd¾œdÄdÅ„Z}�d@eDddÁœdÆdÇ„Z~�dAeeeeeR ee ddÈœdÉdÊ„Z€�dBeeeeeR ddËœdÌdÍ„Z��dCeeeeeR eoepddÎœdÏdÐ„Z‚�dDeeeeeR eoepddÎœdÑdÒ„ZƒdÓZ„ee… dœdÔdÕ„Z†ee… dœdÖd×„Z‡eeVe…f ddØœdÙdÚ„Zˆe…ddØœdÛdÜ„Z‰e…ddØœdÝdÞ„ZŠeee… dœdßdà„ƒZ‹e‹je…ddØœdádà„ƒZ‹eee… dœdâdã„ƒZŒeŒje…ddØœdädã„ƒZŒdåZ�eeŽ dœdædç„Z�eeŽ dœdèdé„Z�eŽddêœdëdì„Z‘eŽddêœdídî„Z’eeeŽ dœdïdð„ƒZ“e“jeŽddêœdñdð„ƒZ“eeeŽ dœdòdó„ƒZ”e”jeŽddêœdôdó„ƒZ”ee;eef ddõœdöd÷„Z•eeef edøœdùdú„Z–eeIee7f eJe—ee˜ f dœdûdü„Z™�dEeee7eIf eedešeJeef eJeeef e&e f edešeJeef eJeeef e&e f eDeee&e eJedýf f  ddþœdÿ�d „Z›egd–�d�d��dFee eeIee7f ee eeœ eDeee&e eJedýf f  d�dœ�d�d„ƒZ�eTe;eef e7e�dœ�d�d„ZžeeŸef e;eef e7d�d	œ�d
�d„Z edeeeeXf e;eef e7ee �dœ�d�d„Z¡eee&eT f ee;eef e7e&e/ �dœ�d�d„Z¢ee;eef e7e&e/ �dœ�d�d„Z£e/e]dCœ�d�d„Z¤�dGe&e/ ee]ef ede]ef d�dœ�d�d„Z¥ddœ�d�d„Z¦�dHe;eef ee§ ee&e  �dœ�d�d„Z¨egd–d—��dIe;eef ee§ ee&e  �dœ�d�d „ƒZ©�dJede7ef ddZœ�d!�d"„ZªdS (K  Ú	PdfWriterz�
    This class supports writing PDF files out, given pages produced by another
    class (typically :class:`PdfReader<PyPDF2.PdfReader>`).
    Ú N)ÚfileobjÚreturnc                 C   sÞ   d| _ g | _i | _i | _tƒ }| ttjƒtdƒttj	ƒt
dƒttjƒtƒ i¡ |  |¡| _tƒ }| tdƒttjd d¡ ƒi¡ |  |¡| _tƒ | _| j ttjƒttjƒttjƒ| ji¡ |  | j¡| _|| _d| _d S )Ns   %PDF-1.3z/Pagesr   z	/ProducerZPyPDF2zutf-16beF)Ú_headerÚ_objectsÚ_idnum_hashÚ_id_translatedr=   ÚupdaterA   ÚPAÚTYPEÚCOUNTrC   ÚKIDSr7   Ú_add_objectÚ_pagesrI   ÚcodecsÚBOM_UTF16_BEÚencodeÚ_infoÚ_root_objectÚCOZCATALOGZPAGESÚ_rootrV   Úwith_as_usage)ÚselfrV   ÚpagesÚinfo© rn   úG/var/www/sistema_ama/venv/lib/python3.9/site-packages/PyPDF2/_writer.pyÚ__init__‹   s:    ýÿÿÿÿþÿzPdfWriter.__init__)rW   c                 C   s
   d| _ | S )z+Store that writer is initialized by 'with'.T)rj   ©rk   rn   rn   ro   Ú	__enter__³   s    zPdfWriter.__enter__)Úexc_typeÚexcÚ	tracebackrW   c                 C   s   | j r|  | j ¡ dS )zWrite data to the fileobj.N)rV   Úwrite)rk   rs   rt   ru   rn   rn   ro   Ú__exit__¸   s    zPdfWriter.__exit__c                 C   s   | j S )zì
        Header of the PDF document that is written.

        This should be something like b'%PDF-1.5'. It is recommended to set the
        lowest version that supports all features which are used within the
        PDF file.
        ©rX   rq   rn   rn   ro   Ú
pdf_headerÂ   s    	zPdfWriter.pdf_header)Ú
new_headerrW   c                 C   s
   || _ d S ©Nrx   )rk   rz   rn   rn   ro   ry   Í   s    ©ÚobjrW   c                 C   sB   t |dƒr|jj| kr|jS | j |¡ tt| jƒd| ƒ|_|jS )NÚindirect_referencer   )Úhasattrr~   ÚpdfrY   Úappendr@   Úlen©rk   r}   rn   rn   ro   ra   Ñ   s
    zPdfWriter._add_object)r~   ÚidorW   c                 C   sp   |d ur*|d urt dƒ‚n|}t dt¡ |d us6J ‚t|tƒrN| j|d  S |j| kr`t dƒ‚| j|jd  S )NzGPlease only set 'indirect_reference'. The 'ido' argument is deprecated.zGThe parameter 'ido' is depreciated and will be removed in PyPDF2 4.0.0.r   zpdf must be self)	Ú
ValueErrorÚwarningsÚwarnÚDeprecationWarningÚ
isinstanceÚintrY   r€   Úidnum)rk   r~   r„   rn   rn   ro   Ú
get_objectØ   s"    ÿþÿ

zPdfWriter.get_object)r„   rW   c                 C   s   t dddƒ |  |¡S )zU
        .. deprecated:: 1.28.0

            Use :meth:`get_object` instead.
        Ú	getObjectrŒ   ú3.0.0)r#   rŒ   )rk   r„   rn   rn   ro   r�   ñ   s    zPdfWriter.getObjectrn   )ÚpageÚactionÚexcluded_keysrW   c                 C   s  t t|tj ƒtjksJ ‚|}t|ƒ}|tjdg7 }z| jt	|j
jƒ |j
j= W n tyb   Y n0 t d| | d|¡ƒ}|jd urª|jj}t|tƒrœ| ¡ }t| j|ƒ| _| j|ttjƒ< t t|  | j¡ƒ}|j
d usÚJ ‚||tj |j
ƒ t t|tj ƒ}t|d ƒ|ttjƒ< |S )Nz/StructParentsr   Fr   )r   Ústrr]   r^   rh   ZPAGEÚlistÚPARENTr[   Úidr~   r€   r‹   Ú	ExceptionÚclonery   r‰   re   r   rb   rA   r=   rŒ   r`   rŠ   r_   rC   )rk   r�   r�   r‘   Zpage_orgÚotherrl   Z
page_countrn   rn   ro   Ú	_add_pageü   s.    ÿ

zPdfWriter._add_pagec              
   C   s�   zV| j }tj|vr6| j  ttjƒtt| jƒd| ƒi¡ ttj	ƒ}t
dƒ| j tj |< W n4 tyŠ } zt dt|ƒ¡ W Y d }~n
d }~0 0 d S )Nr   Tz&set_need_appearances_writer() catch : )rg   r'   Z	ACRO_FORMr\   rA   r@   r‚   rY   r.   ZNeedAppearancesr8   r–   ÚloggerÚerrorÚrepr)rk   ÚcatalogZneed_appearancesrt   rn   rn   ro   Úset_need_appearances_writer  s    

ÿÿÿ
z%PdfWriter.set_need_appearances_writer)r�   r‘   rW   c                 C   s   |   |tj|¡S )ar  
        Add a page to this PDF file.
        Recommended for advanced usage including the adequate excluded_keys

        The page is usually acquired from a :class:`PdfReader<PyPDF2.PdfReader>`
        instance.

        :param PageObject page: The page to add to the document. Should be
            an instance of :class:`PageObject<PyPDF2._page.PageObject>`
        )r™   r“   r�   ©rk   r�   r‘   rn   rn   ro   Úadd_page2  s    zPdfWriter.add_pagec                 C   s   t dddƒ |  ||¡S )zS
        .. deprecated:: 1.28.0

            Use :meth:`add_page` instead.
        ÚaddPager    rŽ   )r#   r    rŸ   rn   rn   ro   r¡   C  s    
zPdfWriter.addPager   )r�   Úindexr‘   rW   c                    s   |   |‡ fdd„¡S )a  
        Insert a page in this PDF file. The page is usually acquired from a
        :class:`PdfReader<PyPDF2.PdfReader>` instance.

        :param PageObject page: The page to add to the document.
        :param int index: Position at which the page will be inserted.
        c                    s   |   ˆ |¡S r{   )Úinsert)ÚlÚp©r¢   rn   ro   Ú<lambda>]  ó    z'PdfWriter.insert_page.<locals>.<lambda>)r™   ©rk   r�   r¢   r‘   rn   r¦   ro   Úinsert_pageP  s    zPdfWriter.insert_pagec                 C   s   t dddƒ |  |||¡S )zV
        .. deprecated:: 1.28.0

            Use :meth:`insert_page` instead.
        Ú
insertPagerª   rŽ   )r#   rª   r©   rn   rn   ro   r«   _  s    zPdfWriter.insertPage)Úpage_numberÚ
pageNumberrW   c                 C   sr   |dur(|durt dƒ‚tdddƒ |}|du r@|du r@t dƒ‚ttttf |  | j¡ƒ}tt|t	j
 |  ¡ ƒS )zÜ
        Retrieve a page by number from this PDF file.

        :param int page_number: The page number to retrieve
            (pages begin at zero)
        :return: the page at the index given by *page_number*
        Nz)Please only use the page_number parameterzget_page(pageNumber)zget_page(page_number)ú4.0.0zPlease specify the page_number)r…   r!   r   r   r’   r	   rŒ   rb   r   r]   r`   )rk   r¬   r­   rl   rn   rn   ro   Úget_pagem  s    
ÿzPdfWriter.get_page)r­   rW   c                 C   s   t dddƒ |  |¡S )zd
        .. deprecated:: 1.28.0

            Use :code:`writer.pages[page_number]` instead.
        ÚgetPagezwriter.pages[page_number]rŽ   )r#   r¯   )rk   r­   rn   rn   ro   r°   „  s    zPdfWriter.getPagec                 C   s*   t tttf |  | j¡ƒ}t|tdƒ ƒS )Nz/Count)r   r   r’   r	   rŒ   rb   rŠ   rA   )rk   rl   rn   rn   ro   Ú_get_num_pages�  s    zPdfWriter._get_num_pagesc                 C   s   t dddƒ |  ¡ S )z\
        .. deprecated:: 1.28.0

            Use :code:`len(writer.pages)` instead.
        ÚgetNumPageszlen(writer.pages)rŽ   )r#   r±   rq   rn   rn   ro   r²   ‘  s    zPdfWriter.getNumPagesc                 C   s   t | j| jƒS )zNProperty that emulates a list of :class:`PageObject<PyPDF2._page.PageObject>`.)r   r±   r¯   rq   rn   rn   ro   rl   š  s    zPdfWriter.pages)ÚwidthÚheightrW   c                 C   s   t  | ||¡}|  |¡ |S )a  
        Append a blank page to this PDF file and returns it. If no page size
        is specified, use the size of the last page.

        :param float width: The width of the new page expressed in default user
            space units.
        :param float height: The height of the new page expressed in default
            user space units.
        :return: the newly appended page
        :raises PageSizeNotDefinedError: if width and height are not defined
            and previous page does not exist.
        )r   Úcreate_blank_pager    )rk   r³   r´   r�   rn   rn   ro   Úadd_blank_pageŸ  s    
zPdfWriter.add_blank_pagec                 C   s   t dddƒ |  ||¡S )zY
        .. deprecated:: 1.28.0

            Use :meth:`add_blank_page` instead.
        ÚaddBlankPager¶   rŽ   )r#   r¶   )rk   r³   r´   rn   rn   ro   r·   ²  s    zPdfWriter.addBlankPage)r³   r´   r¢   rW   c                 C   sX   |du s |du r:|   ¡ d |kr:| j| }|jj}|jj}t | ||¡}|  ||¡ |S )a8  
        Insert a blank page to this PDF file and returns it. If no page size
        is specified, use the size of the last page.

        :param float width: The width of the new page expressed in default user
            space units.
        :param float height: The height of the new page expressed in default
            user space units.
        :param int index: Position to add the page.
        :return: the newly appended page
        :raises PageSizeNotDefinedError: if width and height are not defined
            and previous page does not exist.
        Nr   )r±   rl   Zmediaboxr³   r´   r   rµ   rª   )rk   r³   r´   r¢   Zoldpager�   rn   rn   ro   Úinsert_blank_page½  s     
zPdfWriter.insert_blank_pagec                 C   s   t dddƒ |  |||¡S )zZ
        .. deprecated:: 1.28.0

            Use :meth:`insertBlankPage` instead.
        ÚinsertBlankPager¸   rŽ   )r#   r¸   )rk   r³   r´   r¢   rn   rn   ro   r¹   Ø  s    zPdfWriter.insertBlankPagec              
   C   s¸   d| j vrdS | j d }t|ttfƒr2tt|ƒƒS t|tƒr°z8|dd… \}}|dd… }t|t|ƒƒ}td||ƒW S  t	y¬ } z t	d|› d|› �ƒ‚W Y d}~q´d}~0 0 ndS dS )a�  
        Property to access the opening destination ("/OpenAction" entry in the
        PDF catalog).
        it returns `None` if the entry does not exist is not set.

        :param destination:.
        the property can be set to a Destination, a Page or an string(NamedDest) or
            None (to remove "/OpenAction")

        (value stored in "/OpenAction" entry in the Pdf Catalog)
        ú/OpenActionNr   é   Z
OpenActionzInvalid Destination ú: )
rg   r‰   r’   ÚbytesrI   r7   r>   Útupler<   r–   )rk   Zoar�   ÚtypÚarrayÚfitrt   rn   rn   ro   Úopen_destinationæ  s    


,zPdfWriter.open_destination)ÚdestrW   c                 C   sœ   |d u r*z| j d= W q˜ ty&   Y q˜0 nnt|tƒrHt|ƒ| j tdƒ< nPt|tƒrd|j| j tdƒ< n4t|tƒr˜td|j	d ur‚|j	nt
ƒ tƒj| j tdƒ< d S )Nrº   ZOpening)rg   ÚKeyErrorr‰   r’   rG   rA   r<   Ú
dest_arrayr   r~   rB   r5   ©rk   rÃ   rn   rn   ro   rÂ     s"    


ÿû)Ú
javascriptrW   c              	   C   sÊ   d| j vrtƒ | j ttjƒ< tt| j tj ƒ}d|vrPttdƒtƒ iƒ|tdƒ< tttt|d ƒd ƒ}tƒ }| ttj	ƒtdƒtdƒtdƒtdƒt
|› ƒi¡ | ttt ¡ ƒƒ¡ | |  |¡¡ dS )a  
        Add Javascript which will launch upon opening this PDF.

        :param str javascript: Your Javascript.

        >>> output.add_js("this.print({bUI:true,bSilent:false,bShrinkToFit:true});")
        # Example: This will launch the print window when the PDF is opened.
        z/Namesz/JavaScriptz/Actionú/Sz/JSN)rg   r=   rA   ÚCAÚNAMESr   r7   r\   r]   r^   rG   r�   rI   r’   ÚuuidÚuuid4ra   )rk   rÇ   ÚnamesZjs_listZjsrn   rn   ro   Úadd_js  s&    

ÿÿýÿzPdfWriter.add_jsc                 C   s   t dddƒ |  |¡S )zQ
        .. deprecated:: 1.28.0

            Use :meth:`add_js` instead.
        ÚaddJSrÎ   rŽ   )r#   rÎ   )rk   rÇ   rn   rn   ro   rÏ   ;  s    zPdfWriter.addJS)ÚfilenameÚdatarW   c                 C   sÎ   t ƒ }| |¡ | ttjƒtdƒi¡ tƒ }| tdƒ|i¡ tƒ }| ttjƒtdƒttjƒt	|ƒttj
ƒ|i¡ tƒ }| ttjƒtt	|ƒ|gƒi¡ tƒ }| tdƒ|i¡ | j ttjƒ|i¡ dS )a  
        Embed a file inside the PDF.

        :param str filename: The filename to display.
        :param str data: The data in the file.

        Reference:
        https://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/PDF32000_2008.pdf
        Section 7.11.3
        z/EmbeddedFileú/Fz	/Filespecz/EmbeddedFilesN)r;   Úset_datar\   rA   r]   r^   r=   r,   ÚFrI   ZEFrÉ   rÊ   r7   rg   )rk   rÐ   rÑ   Z
file_entryZef_entryZfilespecZembedded_files_names_dictionaryZembedded_files_dictionaryrn   rn   ro   Úadd_attachmentD  s4    

ÿ
ûÿ

ÿÿÿ
ÿzPdfWriter.add_attachment)ÚfnameÚfdatarW   c                 C   s   t dddƒ |  ||¡S )zY
        .. deprecated:: 1.28.0

            Use :meth:`add_attachment` instead.
        ÚaddAttachmentrÕ   rŽ   )r#   rÕ   )rk   rÖ   r×   rn   rn   ro   rØ   –  s    zPdfWriter.addAttachment)ÚreaderÚafter_page_appendrW   c                 C   s@   t |jƒ}t|ƒD ](}|j| }|  |¡}t|ƒr||ƒ qdS )aÆ  
        Copy pages from reader to writer. Includes an optional callback parameter
        which is invoked after pages are appended to the writer.

        :param PdfReader reader: a PdfReader object from which to copy page
            annotations to this writer object.  The writer's annots
            will then be updated
        :param Callable[[PageObject], None] after_page_append:
            Callback function that is invoked after each page is appended to
            the writer. Signature includes a reference to the appended page
            (delegates to append_pages_from_reader). The single parameter of the
            callback is a reference to the page just appended to the document.
        N)r‚   rl   Úranger    Úcallable)rk   rÙ   rÚ   Zreader_num_pagesZreader_page_numberZreader_pageZwriter_pagern   rn   ro   Úappend_pages_from_reader¡  s    


z"PdfWriter.append_pages_from_readerc                 C   s   t dddƒ |  ||¡ dS )zc
        .. deprecated:: 1.28.0

            Use :meth:`append_pages_from_reader` instead.
        ÚappendPagesFromReaderrÝ   rŽ   N)r#   rÝ   ©rk   rÙ   rÚ   rn   rn   ro   rÞ   ½  s    
ÿzPdfWriter.appendPagesFromReader)r�   ÚfieldsÚflagsrW   c                 C   s  |   ¡  tj|vr tdtƒ dS tt|tj ƒƒD ]Ú}|tj |  ¡ }i }tj|v r`|tj }|D ]¦}| 	t
j¡|krÞ| 	t
j¡dkr¤| ttjƒt|| ƒi¡ | tt
jƒt|| ƒi¡ |rÜ| tt
jƒt|ƒi¡ qd| 	t
j¡|krd| tt
jƒt|| ƒi¡ qdq2dS )a•  
        Update the form field values for a given page from a fields dictionary.

        Copy field texts and values from fields to page.
        If the field links to a parent object, add the information to the parent.

        :param PageObject page: Page reference from PDF writer where the
            annotations and field data will be updated.
        :param dict fields: a Python dictionary of field names (/T) and text
            values (/V)
        :param int flags: An integer (0 to 7). The first bit sets ReadOnly, the
            second bit sets Required, the third bit sets NoExport. See
            PDF Reference Table 8.70 for details.
        z No fields to update on this pageNz/Btn)rž   ÚPGÚANNOTSr$   Ú__name__rÛ   r‚   rŒ   r”   Úgetr*   ÚTZFTr\   rA   r%   ZASÚVrG   ZFfrC   )rk   r�   rà   rá   ÚjZwriter_annotZwriter_parent_annotÚfieldrn   rn   ro   Úupdate_page_form_field_valuesÌ  sN    



ÿ
ýÿ
ÿÿÿ
ÿÿÿ
ÿÿÿz'PdfWriter.update_page_form_field_valuesc                 C   s   t dddƒ |  |||¡S )zh
        .. deprecated:: 1.28.0

            Use :meth:`update_page_form_field_values` instead.
        ÚupdatePageFormFieldValuesrê   rŽ   )r#   rê   )rk   r�   rà   rá   rn   rn   ro   rë     s    ÿz#PdfWriter.updatePageFormFieldValues)rÙ   rW   c                 C   s   t t|jtj ƒ| _dS )zŠ
        Copy the reader document root to the writer.

        :param reader:  PdfReader from the document root should be copied.
        N)r   r=   ÚtrailerÚTKÚROOTrg   ©rk   rÙ   rn   rn   ro   Úclone_reader_document_root  s    z$PdfWriter.clone_reader_document_rootc                 C   s   t dddƒ |  |¡ dS )ze
        .. deprecated:: 1.28.0

            Use :meth:`clone_reader_document_root` instead.
        ÚcloneReaderDocumentRootrð   rŽ   N)r#   rð   rï   rn   rn   ro   rñ   %  s    ÿz!PdfWriter.cloneReaderDocumentRootc                 C   s   |   |¡ |  ||¡ dS )a)  
        Create a copy (clone) of a document from a PDF file reader

        :param reader: PDF file reader instance from which the clone
            should be created.
        :param Callable[[PageObject], None] after_page_append:
            Callback function that is invoked after each page is appended to
            the writer. Signature includes a reference to the appended page
            (delegates to append_pages_from_reader). The single parameter of the
            callback is a reference to the page just appended to the document.
        N)rð   rÝ   rß   rn   rn   ro   Úclone_document_from_reader0  s    
z$PdfWriter.clone_document_from_readerc                 C   s   t dddƒ |  ||¡ dS )ze
        .. deprecated:: 1.28.0

            Use :meth:`clone_document_from_reader` instead.
        ÚcloneDocumentFromReaderrò   rŽ   N)r#   rò   rß   rn   rn   ro   ró   D  s    
ÿz!PdfWriter.cloneDocumentFromReaderT)Úuser_passwordÚowner_passwordÚ
use_128bitÚpermissions_flagÚuser_pwdÚ	owner_pwdrW   c                 C   sô  |dur(|durt dƒ‚nt d¡ |}|du r8t dƒ‚|durx|durRt dƒ‚n&d}d}tj|› d|› d	�td
� |}|du r„|}|ršd}	d}
tdƒ}nd}	d}
tdƒ}|}tt|||
|ƒƒ}tttt	 	¡ ƒ 
d¡ƒ ¡ ƒ}tttt ¡ ƒ 
d¡ƒ ¡ ƒ}t||fƒ| _|
dk�r(t||||ƒ\}}n&|
dk�s6J ‚t||
||||dƒ\}}tƒ }tdƒ|ttjƒ< t|	ƒ|tdƒ< |	dk�r–t|d ƒ|ttjƒ< t|
ƒ|ttjƒ< t|ƒ|ttjƒ< t|ƒ|ttjƒ< t|ƒ|ttjƒ< |  |¡| _|| _dS )a  
        Encrypt this PDF file with the PDF Standard encryption handler.

        :param str user_password: The "user password", which allows for opening
            and reading the PDF file with the restrictions provided.
        :param str owner_password: The "owner password", which allows for
            opening the PDF files without any restrictions.  By default,
            the owner password is the same as the user password.
        :param bool use_128bit: flag as to whether to use 128bit
            encryption.  When false, 40bit encryption will be used.  By default,
            this flag is on.
        :param unsigned int permissions_flag: permissions as described in
            TABLE 3.20 of the PDF 1.7 specification. A bit value of 1 means the
            permission is grantend. Hence an integer value of -1 will set all
            flags.
            Bit position 3 is for printing, 4 is for modifying content, 5 and 6
            control annotations, 9 for form fields, 10 for extraction of
            text and graphics.
        NzGPlease only set 'user_password'. The 'user_pwd' argument is deprecated.z|Please use 'user_password' instead of 'user_pwd'. The 'user_pwd' argument is deprecated and will be removed in PyPDF2 4.0.0.zuser_password may not be NonezIThe argument owner_pwd of encrypt is deprecated. Use owner_password only.rù   rõ   úG is deprecated as an argument and will be removed in PyPDF2 4.0.0. Use ú instead©ÚmessageÚcategoryr»   é   g      0@r   g      @Úutf8Fz	/Standardú/Vé   )r…   r†   r‡   rˆ   rŠ   r9   r   r   rœ   Útimere   ÚdigestÚrandomr7   Ú_IDr   r   r=   rA   ÚSAZFILTERrC   ZLENGTHÚEDÚRÚOÚUÚPra   Ú_encryptÚ_encrypt_key)rk   rô   rõ   rö   r÷   rø   rù   Úold_termÚnew_termrç   ÚrevZkeylenr  r
  ZID_1ZID_2r  ÚkeyÚencryptrn   rn   ro   r  S  sl    ÿÿÿÿû


zPdfWriter.encrypt)ÚstreamrW   c                 C   s‚   t |dƒr(d|jvr(td|j› d�tƒ | js<|  | j¡| _|  | j¡ |  	|¡}|  
||¡}|  |¡ | td|› d�ƒ¡ d S )NÚmodeÚbzFile <zH> to write to is not in binary mode. It may not be written to correctly.z
startxref
z
%%EOF
)r   r  r$   Únamerä   ri   ra   rg   Ú_sweep_indirect_referencesÚ_write_headerÚ_write_xref_tableÚ_write_trailerrv   r    )rk   r  Úobject_positionsÚxref_locationrn   rn   ro   Úwrite_stream±  s    ý


zPdfWriter.write_streamc                 C   s^   d}|dkrt d|› d�ƒ‚t|ttfƒr>t|dƒ}d| _d}|  |¡ | jrV| ¡  ||fS )ae  
        Write the collection of pages added to this object out as a PDF file.

        :param stream: An object to write the file to.  The object can support
            the write method and the tell method, similar to a file object, or
            be a file path, just like the fileobj, just named it stream to keep
            existing workflow.
        FrU   zOutput(stream=z) is empty.ÚwbT)r…   r‰   r’   r   r   rj   r  Úclose)rk   r  Zmy_filern   rn   ro   rv   Ë  s    	

zPdfWriter.writec           
      C   s$  g }|  | jd ¡ |  d¡ t| jƒD ]ö\}}| j| }|d ur(|d }| | ¡ ¡ |  tt|ƒƒd ¡ d }t| dƒ�r|| j	j
k�rt d|d ¡d d… }t dd¡d d	… }| j| | }t|ƒt| jƒd
 ksàJ ‚t|ƒ ¡ }	|	d tdt| jƒd
 ƒ… }| ||¡ |  d¡ q(|S )Nó   
s   %âãÏÓ
r   s    0 obj
r  z<irÿ   r   r»   é   é   s   
endobj
)rv   ry   Ú	enumeraterY   r�   Útellr    r’   r   r  r‹   ÚstructÚpackr  r‚   r   r  ÚminÚwrite_to_stream)
rk   r  r  Úir}   r‹   r  Zpack1Zpack2Zmd5_hashrn   rn   ro   r  å  s(    

zPdfWriter._write_header)r  r  rW   c                 C   s|   |  ¡ }| d¡ | tdt| jƒd › d�ƒ¡ | tdd›ddd	›d
�ƒ¡ |D ]"}| t|d›ddd	›d�ƒ¡ qT|S )Ns   xref
z0 r   Ú
r   z0>10ú iÿÿ  z0>5z f 
z n 
)r%  rv   r    r‚   rY   )rk   r  r  r  Úoffsetrn   rn   ro   r  ü  s    
  zPdfWriter._write_xref_tablec                 C   sŽ   |  d¡ tƒ }| ttjƒtt| jƒd ƒttj	ƒ| j
ttjƒ| ji¡ t| dƒrd| j|ttjƒ< t| dƒr~| j|ttjƒ< | |d ¡ d S )Ns   trailer
r   r  r  )rv   r=   r\   rA   rí   ZSIZErC   r‚   rY   rî   ri   ÚINFOrf   r   r  ZIDr  ZENCRYPTr)  )rk   r  rì   rn   rn   ro   r    s    
ýÿ

zPdfWriter._write_trailer)ÚinfosrW   c                 C   s@   i }t | ¡ ƒD ]\}}t|ƒ|t|ƒ< q|  | j¡ |¡ dS )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.
        N)r“   ÚitemsrI   rA   rŒ   rf   r\   )rk   r/  Úargsr  Úvaluern   rn   ro   Úadd_metadata  s    zPdfWriter.add_metadatac                 C   s   t dddƒ |  |¡ dS )zW
        .. deprecated:: 1.28.0

            Use :meth:`add_metadata` instead.
        ÚaddMetadatar3  rŽ   N)r#   r3  )rk   r/  rn   rn   ro   r4  !  s    zPdfWriter.addMetadata)ÚrootrW   c                 C   s~  t  ¡ }g }d }g }d }| ||||f¡ t|ƒ�rz| ¡ \}}}}t|ttfƒrŠ| ¡ D ],\}}	| |	|||d ur~||g ng f¡ qZnNt|t	ƒrØ|j
| krØ|  |¡}t|ƒ|vrØ| t|ƒ¡ | | ¡ d d g f¡ t|ttfƒr*t|tƒ�r|  |  |¡¡}g }
|| |k�r4| ¡ gdd„ |D ƒ }
|||< |
D ]>}| j |d ¡}|d u�r8| ¡ }|d u�r8|| j| ¡ < �q8q*d S )Nc                 S   s   g | ]}|  ¡ ‘qS rn   )Ú
hash_value)Ú.0Zgrant_parentrn   rn   ro   Ú
<listcomp>j  s   z8PdfWriter._sweep_indirect_references.<locals>.<listcomp>)ÚcollectionsÚdequer�   r‚   Úpopr‰   r7   r=   r0  r@   r€   Ú_resolve_indirect_objectr’   rŒ   rF   ra   r6  rZ   )rk   r5  ÚstackZ
discoveredÚparentZgrant_parentsZ	key_or_idrÑ   r  r2  Zupdate_hashesZold_hashr~   Zindirect_reference_objrn   rn   ro   r  *  sT    ù
üÿ


ÿ

þÿz$PdfWriter._sweep_indirect_references)rÑ   rW   c                 C   sÄ   t |jdƒr*|jjjr*td|jjj› �ƒ‚|j| kr8|S |j |¡}|du rntd|jj	› d|› d�t	ƒ t
ƒ }| ¡ }|| jv rŠ| j| S |j| krªt|jd| ƒ| j|< n|  |¡| j|< | j| S )zÄ
        Resolves indirect object to this pdf indirect objects.

        If it is a new object then it is added to self._objects
        and new idnum is given and generation is always 0.
        r  zI/O operation on closed file: NzUnable to resolve [r¼   z], returning NullObject insteadr   )r   r€   r  Úclosedr…   r  rŒ   r$   Ú	__class__rä   rB   r6  rZ   r@   r‹   ra   )rk   rÑ   Zreal_objr6  rn   rn   ro   r<  {  s$    
ý


z"PdfWriter._resolve_indirect_objectc                 C   s0   | j  |¡d }t|d| ƒ}| ¡ |ks,J ‚|S ©Nr   r   )rY   r¢   r@   rŒ   )rk   r}   r‹   Úrefrn   rn   ro   Úget_reference¡  s    zPdfWriter.get_referencec                 C   s   t dddƒ |  |¡S )zX
        .. deprecated:: 1.28.0

            Use :meth:`get_reference` instead.
        ÚgetReferencerC  rŽ   )r#   rC  rƒ   rn   rn   ro   rD  §  s    zPdfWriter.getReferencec                 C   sz   t j| jv rLtt| jt j ƒ}| j |¡d }t|d| ƒ}| ¡ |ksvJ ‚n*tƒ }| 	i ¡ |  
|¡}|| jtt jƒ< |S rA  )rh   ÚOUTLINESrg   r   rH   rY   r¢   r@   rŒ   r\   ra   rA   )rk   Úoutliner‹   Zoutline_refrn   rn   ro   Úget_outline_root°  s    

zPdfWriter.get_outline_rootc                 C   s:   t j| jv r tt| jt j ƒ}ntƒ }|| jtt jƒ< |S )u¥   
        the list of threads see Â§8.3.2 from PDF 1.7 spec

                :return: an Array (possibly empty) of Dictionaries with "/F" and "/I" properties
        )rh   ZTHREADSrg   r   r7   rA   )rk   Úthreadsrn   rn   ro   Úget_threads_root¿  s
    zPdfWriter.get_threads_rootc                 C   s   |   ¡ S )u´   
        Read-only property for the list of threads see Â§8.3.2 from PDF 1.7 spec

        :return: an Array (possibly empty) of Dictionaries with "/F" and "/I" properties
        )rI  rq   rn   rn   ro   rH  Í  s    zPdfWriter.threadsc                 C   s   t dddƒ |  ¡ S )z[
        .. deprecated:: 1.28.0

            Use :meth:`get_outline_root` instead.
        ÚgetOutlineRootrG  rŽ   )r#   rG  rq   rn   rn   ro   rJ  Ö  s    zPdfWriter.getOutlineRootc                 C   s"  t j| jv rÌt| jt j tƒrÌtt| jt j ƒ}|j}t j|v r˜t|t j tƒr˜tt|t j ƒ}|j}t j|v r‚tt|t j ƒ}qÊtƒ }||t	t jƒ< n2tƒ }|  
|¡}||t	t jƒ< tƒ }||t	t jƒ< nRtƒ }|  
|¡}|| jt	t jƒ< tƒ }|  
|¡}||t	t jƒ< tƒ }||t	t jƒ< |S r{   )rÉ   rÊ   rg   r‰   r=   r   r~   ZDESTSr7   rA   ra   )rk   rÍ   Z	names_refZdestsZ	dests_refÚndrn   rn   ro   Úget_named_dest_rootß  s4    ÿ



zPdfWriter.get_named_dest_rootc                 C   s   t dddƒ |  ¡ S )z^
        .. deprecated:: 1.28.0

            Use :meth:`get_named_dest_root` instead.
        ÚgetNamedDestRootrL  rŽ   )r#   rL  rq   rn   rn   ro   rM    s    zPdfWriter.getNamedDestRoot)Úpage_destinationr>  ÚbeforerÃ   rW   c                 C   sž   |d ur|d urt dƒ‚|d urFd}d}tj|› d|› d�td� |}|d u rVt dƒ‚|d u rf|  ¡ }tt| ¡ ƒ}|  |¡}|d urŒ|j	}| 
||| ¡ |S )Nz[The argument dest of add_outline_item_destination is deprecated. Use page_destination only.rÃ   rN  rú   rû   rü   ú page_destination may not be None)r…   r†   r‡   rˆ   rG  r   rH   rŒ   ra   r~   Úinsert_child)rk   rN  r>  rO  rÃ   r  r  Úpage_destination_refrn   rn   ro   Úadd_outline_item_destination  s0    ÿÿû
z&PdfWriter.add_outline_item_destination)rÃ   r>  rW   c                 C   s   t dddƒ |  ||¡S )zf
        .. deprecated:: 2.9.0

            Use :meth:`add_outline_item_destination` instead.
        Úadd_bookmark_destinationrS  rŽ   ©r#   rS  ©rk   rÃ   r>  rn   rn   ro   rT  0  s    
ÿz"PdfWriter.add_bookmark_destinationc                 C   s   t dddƒ |  ||¡S )zg
        .. deprecated:: 1.28.0

            Use :meth:`add_outline_item_destination` instead.
        ÚaddBookmarkDestinationrS  rŽ   rU  rV  rn   rn   ro   rW  ?  s    ÿz PdfWriter.addBookmarkDestinationÚoutline_item)Úbookmark)rX  r>  rO  rW   c           
      C   sœ   t ƒ }t| ¡ ƒD ]\}}||tt|ƒƒ< q| |¡ d|v rŽtƒ }tt|d ƒ}t| ¡ ƒD ]\}}||tt|ƒƒ< q^|  |¡}	|	|tdƒ< |  	|||¡S )Nú/A)
rH   r“   r0  rA   r’   r\   r=   r   ra   rS  )
rk   rX  r>  rO  Zoutline_item_objectÚkÚvr�   Za_dictÚ
action_refrn   rn   ro   Úadd_outline_item_dictL  s    

zPdfWriter.add_outline_item_dict)rX  r>  rW   c                 C   s   t dddƒ |  ||¡S )z_
        .. deprecated:: 2.9.0

            Use :meth:`add_outline_item_dict` instead.
        Úadd_bookmark_dictr^  rŽ   ©r#   r^  ©rk   rX  r>  rn   rn   ro   r_  b  s    	ÿzPdfWriter.add_bookmark_dictc                 C   s   t dddƒ |  ||¡S )z`
        .. deprecated:: 1.28.0

            Use :meth:`add_outline_item_dict` instead.
        ÚaddBookmarkDictr^  rŽ   r`  ra  rn   rn   ro   rb  p  s    	ÿzPdfWriter.addBookmarkDictF)
Útitler¬   r>  rO  ÚcolorÚboldÚitalicrÁ   ÚpagenumrW   c
              
   C   sB  t |tƒr6|dur|du r|}|  |||d||||¡S |durN|	durNtdƒ‚|du r\d}
n¶t |tƒrl|}nHt |tƒr~|j}n6t |tƒr´z| j| j}W n t	y²   t
|ƒ}Y n0 |du rÒtd|› �tƒ tƒ }ttd| d ƒ||ƒ}|  tttjƒ|jttjƒtdƒiƒ¡}
t|
||||ƒ}|du �r4|  ¡ }|  |||¡S )añ  
        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 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 or as a Hex String (#RRGGBB)
        :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.
        NúMThe argument pagenum of add_outline_item is deprecated. Use page_number only.zcan not find reference of page ú/z outline itemú/GoTo)r‰   r>   Úadd_outline_itemr…   r@   r   r~   rŠ   rl   Ú
IndexErrorrC   r$   rä   rB   r<   rA   ra   r=   r-   ÚDrÅ   ÚSÚ_create_outline_itemrG  rS  )rk   rc  r¬   r>  rO  rd  re  rf  rÁ   rg  r]  Úpage_refrÃ   rX  rn   rn   ro   rk  ~  sV    
ÿÿ


þýþÿÿ
zPdfWriter.add_outline_itemú/Fit)	rc  rg  r>  rd  re  rf  rÁ   r1  rW   c           	      G   s*   t dddƒ |  ||||||t||d�¡S )zZ
        .. deprecated:: 2.9.0

            Use :meth:`add_outline_item` instead.
        Úadd_bookmarkrk  rŽ   ©Zfit_typeÚfit_args©r#   rk  r>   ©	rk   rc  rg  r>  rd  re  rf  rÁ   r1  rn   rn   ro   rr  Ê  s    
ùzPdfWriter.add_bookmarkc           	      G   s,   t dddƒ |  |||d|||t||d�¡S )z[
        .. deprecated:: 1.28.0

            Use :meth:`add_outline_item` instead.
        ÚaddBookmarkrk  rŽ   Nrs  ru  rv  rn   rn   ro   rw  å  s    
øzPdfWriter.addBookmarkc                 C   s   t dƒ‚d S )NzIThis method is not yet implemented. Use :meth:`add_outline_item` instead.)ÚNotImplementedErrorrq   rn   rn   ro   Úadd_outline  s    ÿzPdfWriter.add_outline)rc  ÚdestinationrW   c                 C   sd   |   ¡ }d}|t|ƒk rN||| k rD| ||¡ | |t|ƒ¡ d S |d7 }q| t|ƒ|g¡ d S )Nr   r»   )rL  r‚   r£   rG   Úextend)rk   rc  rz  rK  r*  rn   rn   ro   Úadd_named_destination_array  s    
z%PdfWriter.add_named_destination_array)rN  rÃ   rW   c                 C   s|   |d ur|d urt dƒ‚|d urFd}d}tj|› d|› d�td� |}|d u rVt dƒ‚|  |j¡}|  td|d	 ƒ|¡ |S )
Nz[The argument dest of add_named_destination_object is deprecated. Use page_destination only.rÃ   rN  rú   rû   rü   rP  rG   ú/Title)r…   r†   r‡   rˆ   ra   rÅ   r|  r   )rk   rN  rÃ   r  r  rR  rn   rn   ro   Úadd_named_destination_object  s*    ÿÿûÿz&PdfWriter.add_named_destination_objectc                 C   s   t dddƒ |  |¡S )zg
        .. deprecated:: 1.28.0

            Use :meth:`add_named_destination_object` instead.
        ÚaddNamedDestinationObjectr~  rŽ   )r#   r~  rÆ   rn   rn   ro   r  3  s    ÿz#PdfWriter.addNamedDestinationObject)rc  r¬   rg  rW   c           
      C   sâ   |d ur|d urt dƒ‚|d urFd}d}tj|› d|› d�td� |}|d u rVt dƒ‚|  | j¡tj | }tƒ }| 	t
tjƒt|t
tjƒtdƒgƒt
tjƒt
d	ƒi¡ |  |¡}|  ¡ }	t|tƒsÐtt|ƒƒ}|	 ||g¡ |S )
Nrh  rg  r¬   rú   rû   rü   zpage_number may not be Nonei:  rj  )r…   r†   r‡   rˆ   rŒ   rb   r]   r`   r=   r\   rA   r-   rm  r7   r3   ZFIT_HrC   rn  ra   rL  r‰   rG   r’   r{  )
rk   rc  r¬   rg  r  r  rp  rÃ   Zdest_refrK  rn   rn   ro   Úadd_named_destination@  s>    ÿÿû
ÿüÿ	

zPdfWriter.add_named_destination)rc  rg  rW   c                 C   s   t dddƒ |  ||¡S )z`
        .. deprecated:: 1.28.0

            Use :meth:`add_named_destination` instead.
        ÚaddNamedDestinationr€  rŽ   )r#   r€  )rk   rc  rg  rn   rn   ro   r�  i  s    ÿzPdfWriter.addNamedDestinationc                 C   sR   t t|  | j¡ƒ}t t|tj ƒ}|D ]&}t t|  |¡ƒ}tj|v r&|tj= q&dS )z.Remove links and annotations from this output.N)	r   r=   rŒ   rb   r7   r]   r`   râ   rã   )rk   Úpg_dictrl   r�   rp  rn   rn   ro   Úremove_linksv  s    
zPdfWriter.remove_linksc                 C   s   t dddƒ |  ¡ S )zW
        .. deprecated:: 1.28.0

            Use :meth:`remove_links` instead.
        ÚremoveLinksrƒ  rŽ   )r#   rƒ  rq   rn   rn   ro   r„    s    zPdfWriter.removeLinks)Úignore_byte_string_objectrW   c                 C   st  t t|  | j¡ƒ}t t|tj ƒ}d}|D �]B}t t|  |¡ƒ}|d  ¡ }t|tƒs`t||ƒ}g }d}	|j	D ]è\}
}|dv r |
d }|ržt|t
ƒsžt
ƒ |
d< nn|dkrÊ|
d }|rÈt|t
ƒsÈt
ƒ |
d< nD|dk�rtt|
d ƒƒD ](}|rät|
d | t
ƒsät
ƒ |
d |< qä|d	k�rd
}	|dk�r*d}	|	�r<||v �r<qn|dk�rHqn| |
|f¡ qn||_	| tdƒ|¡ q*dS )zž
        Remove images from this output.

        :param bool ignore_byte_string_object: optional parameter
            to ignore ByteString Objects.
        )s   cmó   wó   Jó   jó   Mó   ds   rió   is   gsó   Wó   bó   só   Só   fó   Fó   nó   mó   ló   có   vó   yó   hó   Bs   Dos   shú	/ContentsF©s   Tjó   'r   ó   "r»   ó   TJó   qTó   Qs   reN)r   r=   rŒ   rb   r7   r]   r`   r‰   r:   Ú
operationsrG   rÛ   r‚   r�   Ú__setitem__rA   )rk   r…  r‚  rl   Zjump_operatorsr�   rp  ÚcontentZ_operationsZseq_graphicsÚoperandsÚoperatorÚtextr*  rn   rn   ro   Úremove_imagesˆ  sP    


ÿÿ
ÿ


zPdfWriter.remove_images)ÚignoreByteStringObjectrW   c                 C   s   t dddƒ |  |¡S )zX
        .. deprecated:: 1.28.0

            Use :meth:`remove_images` instead.
        ÚremoveImagesr§  rŽ   )r#   r§  ©rk   r¨  rn   rn   ro   r©  Õ  s    zPdfWriter.removeImagesc                 C   s€  t t|  | j¡ƒ}t tt |tj ƒ}|D �]N}t t|  |¡ƒ}|d  ¡ }t	|t
ƒs`t
||ƒ}|jD �] \}}|dv r´|d }	|sšt	|	tƒr²tƒ |d< nt	|	ttfƒr²tƒ |d< qf|dkrø|d }	|sÞt	|	tƒrötƒ |d< nt	|	ttfƒrötƒ |d< qf|dkrftt|d ƒƒD ]V}
|�s>t	|d |
 tƒ�rdtƒ |d |
< n&t	|d |
 ttfƒ�rtƒ |d |
< �qqf| tdƒ|¡ q*dS )zœ
        Remove text from this output.

        :param bool ignore_byte_string_object: optional parameter
            to ignore ByteString Objects.
        rš  r›  r   r�  r»   rž  N)r   r=   rŒ   rb   r   r@   r]   r`   r   r‰   r:   r¡  rG   r9   rÛ   r‚   r¢  rA   )rk   r…  r‚  rl   r�   rp  r£  r¤  r¥  r¦  r*  rn   rn   ro   Úremove_textà  s@    




ÿzPdfWriter.remove_textc                 C   s   t dddƒ |  |¡S )zV
        .. deprecated:: 1.28.0

            Use :meth:`remove_text` instead.
        Ú
removeTextr«  rŽ   )r#   r«  rª  rn   rn   ro   r¬    s    zPdfWriter.removeText)r¬   ÚuriÚrectÚborderrg  rW   c                 C   s–  |durt jdtd� |}|  | j¡tj | }ttt	t
f |  |¡ƒ}|dur”dd„ |dd… D ƒ}t|ƒdkr¢tdd„ |d D ƒƒ}	| |	¡ ntd	ƒgd }t|t	ƒr¶t|ƒ}nt|tƒrÂnt|ƒ}tƒ }
|
 td
ƒtdƒtdƒt|ƒi¡ tƒ }| ttjƒttjƒttjƒtdƒttjƒ|ttjƒ|tdƒtdƒttjƒt|ƒtdƒ|
i¡ |  |¡}tj|v �r~|tj  |¡ nt|gƒ|ttjƒ< dS )aç  
        Add an URI from a rectangular area to the specified page.
        This uses the basic structure of :meth:`add_link`

        :param int page_number: index of the page on which to place the URI action.
        :param str uri: URI of resource to link to.
        :param Tuple[int, int, int, int] rect: :class:`RectangleObject<PyPDF2.generic.RectangleObject>` or array of four
            integers specifying the clickable rectangular area
            ``[xLL, yLL, xUR, yUR]``, or string in the form ``"[ xLL yLL xUR yUR ]"``.
        :param ArrayObject border: if provided, an array describing border-drawing
            properties. See the PDF spec for details. No border will be
            drawn if this argument is omitted.
        NzoThe 'pagenum' argument of add_uri is deprecated and will be removed in PyPDF2 4.0.0. Use 'page_number' instead.)rþ   c                 S   s   g | ]}t |ƒ‘qS rn   ©rA   ©r7  Únrn   rn   ro   r8  8  r¨   z%PdfWriter.add_uri.<locals>.<listcomp>rÿ   é   c                 S   s   g | ]}t |ƒ‘qS rn   r°  r±  rn   rn   ro   r8  :  r¨   r»   rÈ   z/URIú/Linkz/Hú/IrZ  )r†   r‡   rˆ   rŒ   rb   r]   r`   r   r   r’   r	   r‚   r7   r�   rC   r‰   rA   rE   r=   r\   rG   r%   r   râ   rã   ZSubtyper  ZRectZBorderra   )rk   r¬   r­  r®  r¯  rg  Z	page_linkrp  Z
border_arrZdash_patternZlnk2ZlnkZlnk_refrn   rn   ro   Úadd_uri  sT    ý


þÿ


ÿ÷ÿ
zPdfWriter.add_uri)rg  r­  r®  r¯  rW   c                 C   s   t dddƒ |  ||||¡S )zR
        .. deprecated:: 1.28.0

            Use :meth:`add_uri` instead.
        ÚaddURIr¶  rŽ   )r#   r¶  )rk   rg  r­  r®  r¯  rn   rn   ro   r·  b  s    zPdfWriter.addURI)rg  rN  r®  r¯  rÁ   r1  rW   c                 G   sz   t ddƒ t|tƒr>| ¡ dd… }tdd„ | d¡D ƒƒ}nt|tƒrJnt|ƒ}tj|||t||d�d	�}| j	||d
�S )NÚadd_linkú+add_annotation(AnnotationBuilder.link(...))r   éÿÿÿÿc                 S   s    g | ]}t |ƒd krt|ƒ‘qS )r   )r‚   Úfloat)r7  Únumrn   rn   ro   r8  �  r¨   z&PdfWriter.add_link.<locals>.<listcomp>r,  rs  )r®  r¯  Útarget_page_indexrÁ   )r¬   Ú
annotation)
r#   r‰   r’   ÚstriprE   Úsplitr6   Úlinkr>   Úadd_annotation)rk   rg  rN  r®  r¯  rÁ   r1  r¾  rn   rn   ro   r¸  q  s$    	ÿ
ÿ

üzPdfWriter.add_linkc                 G   s&   t dddƒ | j|||||g|¢R Ž S )zS
        .. deprecated:: 1.28.0

            Use :meth:`add_link` instead.
        ÚaddLinkr¹  r®   )r!   r¸  )rk   rg  rN  r®  r¯  rÁ   r1  rn   rn   ro   rÃ  �  s    ÿzPdfWriter.addLink)z	/NoLayoutz/SinglePagez
/OneColumnz/TwoColumnLeftz/TwoColumnRightz/TwoPageLeftz/TwoPageRightc                 C   s,   zt t| jd ƒW S  ty&   Y d S 0 d S )Nú/PageLayout)r   rO   rg   rÄ   rq   rn   rn   ro   Ú_get_page_layout­  s    zPdfWriter._get_page_layoutc                 C   s   t dddƒ |  ¡ S )úY
        .. deprecated:: 1.28.0

            Use :py:attr:`page_layout` instead.
        ÚgetPageLayoutÚpage_layoutrŽ   )r#   rÅ  rq   rn   rn   ro   rÇ  ³  s    zPdfWriter.getPageLayout)ÚlayoutrW   c                 C   sP   t |tƒs8|| jvr0tddd | j¡f› �tƒ t|ƒ}| j tdƒ|i¡ dS )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
        zLayout should be one of: rU   rÄ  N)r‰   rA   Ú_valid_layoutsr$   Újoinrä   rg   r\   ©rk   rÉ  rn   rn   ro   Ú_set_page_layout¼  s    

þzPdfWriter._set_page_layoutc                 C   s   |   |¡ dS )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©rÍ  rÌ  rn   rn   ro   Úset_page_layoutÝ  s    zPdfWriter.set_page_layoutc                 C   s   t dddƒ |  |¡S )rÆ  zwriter.setPageLayout(val)zwriter.page_layout = valrŽ   )r#   rÍ  rÌ  rn   rn   ro   ÚsetPageLayout÷  s    ÿzPdfWriter.setPageLayoutc                 C   s   |   ¡ S )aÛ  
        Page layout property.

        .. list-table:: Valid ``layout`` values
           :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
        )rÅ  rq   rn   rn   ro   rÈ    s    zPdfWriter.page_layoutc                 C   s   |   |¡ d S r{   rÎ  rÌ  rn   rn   ro   rÈ    s    c                 C   s   t dddƒ | jS )rÆ  Ú
pageLayoutrÈ  rŽ   ©r#   rÈ  rq   rn   rn   ro   rÑ    s    zPdfWriter.pageLayoutc                 C   s   t dddƒ || _dS )rÆ  rÑ  rÈ  rŽ   NrÒ  rÌ  rn   rn   ro   rÑ  )  s    )z/UseNonez/UseOutlinesz
/UseThumbsz/FullScreenz/UseOCz/UseAttachmentsc                 C   s,   zt t| jd ƒW S  ty&   Y d S 0 d S )Nú	/PageMode)r   rR   rg   rÄ   rq   rn   rn   ro   Ú_get_page_mode<  s    zPdfWriter._get_page_modec                 C   s   t dddƒ |  ¡ S )úW
        .. deprecated:: 1.28.0

            Use :py:attr:`page_mode` instead.
        ÚgetPageModeÚ	page_moderŽ   )r#   rÔ  rq   rn   rn   ro   rÖ  B  s    zPdfWriter.getPageMode)r  rW   c                 C   sR   t |tƒr|}n*|| jvr2tdd | j¡› �tƒ t|ƒ}| j tdƒ|i¡ dS )rÕ  zMode should be one of: z, rÓ  N)r‰   rA   Ú_valid_modesr$   rË  rä   rg   r\   )rk   r  Z	mode_namern   rn   ro   Úset_page_modeK  s    

ÿzPdfWriter.set_page_modec                 C   s   t dddƒ |  |¡ dS )rÕ  zwriter.setPageMode(val)zwriter.page_mode = valrŽ   N)r#   rÙ  ©rk   r  rn   rn   ro   ÚsetPageMode[  s    ÿzPdfWriter.setPageModec                 C   s   |   ¡ S )a  
        Page mode property.

        .. list-table:: Valid ``mode`` values
           :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
        )rÔ  rq   rn   rn   ro   r×  f  s    zPdfWriter.page_modec                 C   s   |   |¡ d S r{   )rÙ  rÚ  rn   rn   ro   r×  }  s    c                 C   s   t dddƒ | jS )rÕ  ÚpageModer×  rŽ   ©r#   r×  rq   rn   rn   ro   rÜ  �  s    zPdfWriter.pageModec                 C   s   t dddƒ || _dS )rÕ  rÜ  r×  rŽ   NrÝ  rÚ  rn   rn   ro   rÜ  ‹  s    )r¬   r¾  rW   c                 C   sÖ   t tt|ƒƒ}|  | j¡d | |tdƒ< | j| }|jd u rLtƒ |tdƒ< |jd usZJ ‚| 	d¡dkr¼tdƒ|v r¼t t
|tdƒ ƒ}ttdƒ|d t|d	 t
|ƒd
 d�ƒ}|j|tdƒ< |  |¡}|j |¡ d S )Nz/Kidsú/Pú/Annotsú/Subtyper´  ú/Destz	/LinkNamer½  rÁ   rt  rs  )r   r=   Ú_pdf_objectifyrŒ   rb   rA   rl   Úannotationsr7   rå   Údictr<   r>   rÅ   ra   r�   )rk   r¬   r¾  Úto_addr�   ÚtmprÃ   Zind_objrn   rn   ro   rÂ  •  s$    

ÿý
zPdfWriter.add_annotation)r�   rW   c                 C   s–   t d| ¡ ƒ}| dg ¡D ]v}| ¡ }| dd¡}| dd¡}t|tƒrZt|ƒ|tdƒ< q|dur| ¡ }| dd¡}t|tƒrt|ƒ|tdƒ< q|S )zŸ
        Perform some clean up in the page.
        Currently: convert NameObject nameddestination to TextStringObject (required for names/dests list)
        r   rß  rá  NrZ  ú/D)r   rŒ   rå   r‰   rA   rG   )rk   r�   ÚaZa_objÚdZactrn   rn   ro   Ú
clean_page®  s    

zPdfWriter.clean_pagec                 C   sÒ   d }t |ttfƒrJt|dƒ�}t| ¡ ƒ}W d   ƒ qÊ1 s>0    Y  n€t |tƒr’|jr`|j}|j 	¡ }|j 
d¡ t|j ¡ ƒ}|j 
|¡ n8t|dƒrÂt|dƒrÂ| 
d¡ | ¡ }t|ƒ}ntdƒ‚||fS )NÚrbr   ÚseekÚreadzÝPdfMerger.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.)r‰   r’   r   r   r   rí  r   Ú_encryptionr  r%  rì  r   rx  )rk   rV   Úencryption_objÚfr  Z	orig_tellZfilecontentrn   rn   ro   Ú_create_streamÁ  s&    	,



ÿzPdfWriter._create_stream.)rV   rX  rl   Úimport_outlineÚexcluded_fieldsrW   c                 C   sj   |du rd}t |tttfƒrRt |tƒr8t |tƒs4|}|}|}|  d|d|||¡ n|  d|||||¡ dS )a0  
        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 a string to build an outline
            (aka 'bookmark') to identify the
            beginning of the included file.

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

        :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``.

        :param List excluded_fields: provide the list of fields/keys to be ignored
            if "/Annots" is part of the list, the annotation will be ignored
            if "/B" is part of the list, the articles will be ignored
        Nrn   )r‰   r¾   r“   rK   ÚboolÚmerge)rk   rV   rX  rl   rò  ró  rn   rn   ro   r�   å  s    '

ÿzPdfWriter.appendrò  )rY  Zimport_bookmarks)ÚpositionrV   rX  rl   rò  ró  rW   c                 C   s°  t |tƒr|}n|  |¡\}}	t|dd�}|du r6d}|du rTttdt|jƒƒƒ}nft |tƒrxtt| t|jƒ¡Ž ƒ}nBt |tƒr„n6t |t	ƒr¨t|ƒdkr¨tt|Ž ƒ}nt |t	ƒsºt
dƒ‚i }
|D ]€}|j| }|jdusÞJ ‚|du �r
|  |t|ƒdd	g ¡|
|jj< n*|  ||t|ƒdd	g ¡|
|jj< |d
7 }||
|jj _qÂ|j|_|j ¡ D ]Z}|j}t |d tƒ�rrn<|d jj|
v �rV|
|d jj j|tdƒ< |  |d |¡ �qV|du�rêtd| jt|ƒt|
 ¡ ƒd jtd� ¡ ƒ}n|  ¡ }td|jtj ƒ}|�r<t j!|v �r<|  "| #t j!d¡|
|¡}|  $||d¡ d	|v�r”|
 ¡ D ]D}|  %|j #d	d¡||
|¡}t|ƒdk�r†||t&d	ƒ< |  '|¡ �qNd|v�r¬|  (d|
|¡ dS )ae  
        Merge the pages from the given file into the output file at the
        specified page number.

        :param int position: 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 a string to build an outline
            (aka 'bookmark') to identify the
            beginning of the included file.

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

        :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``.

        :param List excluded_fields: provide the list of fields/keys to be ignored
            if "/Annots" is part of the list, the annotation will be ignored
            if "/B" is part of the list, the articles will be ignored
        F)ÚstrictNrn   r   rÿ   z:"pages" must be a tuple of (start, stop[, step]) or a listú/Brß  r   ú/Pager}  rH   )rÁ   r=   rU   ))r‰   r   rñ  r“   rÛ   r‚   rl   rK   Úindicesr¾   Ú	TypeErrorr~   r    r‹   rª   Úoriginal_pageZnamed_destinationsZ_namedDestsÚvaluesrÅ   rB   rC   r|  r   rk  rG   r5   rŒ   rG  rì   rí   rî   rh   rE  Ú_get_filtered_outlinerå   Ú_insert_filtered_outlineÚ_insert_filtered_annotationsrA   rê  Úadd_filtered_articles)rk   rö  rV   rX  rl   rò  ró  rÙ   r  rï  Zsrcpagesr*  ZpgrÃ   ÚarrZoutline_item_typZ_rorF  ÚpagÚlstrn   rn   ro   rõ  	  sŽ    '



ÿ

ÿÿÿ
ÿ
ýþ	ÿÿ
ÿ
zPdfWriter.merge)Úthreadrl   rÙ   rW   c                 C   sz  |j | ddd�}| j |j¡ td|d ƒ}|}d}|du�rd|  td|d ƒ||¡}|du�r,|du r’td|  tƒ ¡ ¡ ƒ}|}	|j|t	dƒ< n4td|  tt	d	ƒ|jiƒ¡ ¡ ƒ}
|
j|t	d
ƒ< |
}||t	dƒ< |j|t	dƒ< |d |t	dƒ< td| ¡ ƒ}d|v�rt
ƒ |t	dƒ< td|d ƒ |j¡ td|d
 ƒ}||kr4|	j|t	d
ƒ< |j|	t	d	ƒ< d}q4|jdu�stJ ‚|jS )zE
        clone the thread with only the applicable articles

        T)rÒ   )Zforce_duplicateÚignore_fieldsr=   rÒ   Nr   rÞ  r  z/Nú/Tz/Rrø  r7   )r—   rH  r�   r~   r   Ú_get_cloned_pagera   r=   rŒ   rA   r7   )rk   r  rl   rÙ   ZnthreadZfirst_articleZcurrent_articleZnew_articler  Z	new_firstZnew_article2Zpag_objrn   rn   ro   Ú_add_articles_threadœ	  sZ    
ÿ
ÿ
þÿÿþ
ÿzPdfWriter._add_articles_thread)Úfltrrl   rÙ   rW   c                 C   s–   t |tƒrt |¡}nt |tƒs*t d¡}| ¡ D ]^}|j}| dd¡D ]F}| ¡ d }|j	j
| jt|ƒ vrH| |d d ¡rH|  |||¡ qHq2dS )z<
        Add articles matching the defined criteria
        rU   rø  rn   r  rµ  r}  N)r‰   r’   ÚreÚcompiler   rý  rü  rå   rŒ   r~   r‹   r[   r•   Úsearchr	  )rk   r
  rl   rÙ   r¥   Úpprè  Zthrrn   rn   ro   r  Õ	  s    	



ÿþzPdfWriter.add_filtered_articles)r�   rl   rÙ   rW   c                 C   s~   t |tƒrd S t |tƒr&|j| j}n0t |tƒrH| dd¡dkrH|j}nt |tƒrV|}z||j jW S  t	yx   Y d S 0 d S )Nú/TyperU   rù  )
r‰   rB   rŠ   rl   r~   r=   rå   r@   r‹   r–   )rk   r�   rl   rÙ   Z_irn   rn   ro   r  ë	  s    


zPdfWriter._get_cloned_page)Úannotsr�   rl   rÙ   rW   c                 C   sÖ  t ƒ }t|tƒrtd| ¡ ƒ}|D �]¬}td| ¡ ƒ}|d dksjd|vsjtd|d ƒd dksjd|v �rd|vr†| | | ¡j¡ n”|d }t|tƒr¼t|ƒ|  	¡ v rº| | | ¡j¡ n^td	|ƒ}|  
|d
 ||¡}	|	d u�rÐ|j| dd�}
t |	g|dd …  ƒ|
tdƒ< | |
j¡ q"td|d ƒd }t|tƒ�r`t|ƒ|  	¡ v �rÐ| | | ¡j¡ q"td	|ƒ}|  
|d
 ||¡}	|	d ur"|j| dd�}
td|
ƒ}
t |	g|dd …  ƒtd|
d ƒtdƒ< | |
j¡ q"|S )Nr   r=   rà  r´  rZ  rÈ   rj  rá  r7   r   )rá  )r  r   rç  )rç  )r7   r‰   r@   r   rŒ   r�   r—   r~   r’   rL  r  rA   )rk   r  r�   rl   rÙ   ZoutlistZanZanoré  r¥   Zancrn   rn   ro   r    
  sP    


ÿþýü




þÿz&PdfWriter._insert_filtered_annotations)Únoderl   rÙ   rW   c                 C   s  g }|  ¡ }| dd¡dks$d|vrT| dd¡}|durþ|  ¡ }||  |||¡7 }nª|durþ|  ¡ }td| |¡ƒ}|  td|d	 ƒ||¡}|du rštƒ }||td	ƒ< d|v rÄ|  |d ||¡|_ng |_t	|d	 tƒræt
|jƒd
krð| |¡ | dd¡}qT|S )zEExtract outline item entries that are part of the specified page set.r  rU   ú	/Outlinesr}  ú/FirstNr<   r   rù  r   ú/Next)rŒ   rå   rþ  r   Z_build_outline_itemr  rB   rA   Úchildsr‰   r‚   r�   )rk   r  rl   rÙ   Znew_outlineÚor\  rn   rn   ro   rþ  3
  s*    
zPdfWriter._get_filtered_outlinec                 C   sÂ   t ƒ }|  |¡ t|d ƒ|tdƒ< t|d tƒsn|jd ur`d|jv r`|jd  | ¡|tdƒ< n|j|tdƒ< |jd ur¾t	|j 
dd¡ƒ|tdƒ< t|j 
dtdƒtdƒtdƒg¡ƒ|tdƒ< |S )	Nr}  rù  rZ  rá  rÒ   r   ú/Cg        )rH   ra   rG   rA   r‰   rB   r  r—   rÅ   rC   rå   r7   r?   )rk   rÃ   Zn_olrn   rn   ro   Ú_clone_outlineS
  s    

ÿÿzPdfWriter._clone_outline)Úoutlinesr>  rO  rW   c                 C   s^   |D ]T}|  dd¡dks d|vr&|}n"|  |¡}tt| ¡ ƒ ||| ¡ |  |j|d ¡ qd S )Nr  rU   r  r}  )rå   r  r   rH   rŒ   rQ  rÿ  r  )rk   r  r>  rO  rÃ   Únprn   rn   ro   rÿ  j
  s    
z"PdfWriter._insert_filtered_outlinec                 C   s   dS )z"To match the functions from MergerNrn   rq   rn   rn   ro   r   z
  s    zPdfWriter.close)rX  r5  rW   c                 C   sª   |d u r|   ¡ }n
td|ƒ}d}|d ur¦|j|ksB| dd ¡|krH|gS d|v r€|  |tt|d ƒ¡}|r€d|v rx|gng | S d|v r |d7 }tt|d ƒ}q d S q d S )NrH   r   r}  r  r  r   )rG  r   r~   rå   Úfind_outline_itemrQ   rH   )rk   rX  r5  r  r*  Úresrn   rn   ro   r  
  s(    

ÿþÿzPdfWriter.find_outline_itemc                 C   s   |   ||¡S )zZ
        .. deprecated:: 2.9.0
            Use :meth:`find_outline_item` instead.
        )r  )rk   rX  r5  rn   rn   ro   Úfind_bookmark�
  s    
zPdfWriter.find_bookmarkc                 C   s~   |du ri | _ njt|tƒr@z| j t|ƒ= W qz ty<   Y qz0 n:t|tƒrrz| j t|jƒ= W qz tyn   Y qz0 ntdƒ‚dS )a)  
        reset the translation table between reader and the writer object.
        late cloning will create new independent objects

        :param reader: PdfReader or IndirectObject refering a PdfReader object.
                       if set to None or omitted, all tables will be reset.
        Nzinvalid parameter {reader})r[   r‰   r   r•   r–   r@   r€   rï   rn   rn   ro   Úreset_translation©
  s    


zPdfWriter.reset_translation)rU   )NN)rn   )rn   )rn   )r   rn   )r   rn   )NN)NN)NN)NNr   )NNr   )N)N)N)N)NNNN)N)N)NN)N)N)NNFFrq  )NNFFrq  )NN)NN)F)F)F)F)NN)N)Nrq  )Nrq  )NNTN)NNTrn   )N)N)N)N)«rä   Ú
__module__Ú__qualname__Ú__doc__r   rp   rr   r   r   ÚBaseExceptionr   rw   Úpropertyr½   ry   ÚsetterrD   r@   ra   r   rŠ   rŒ   r�   r   r
   r	   r   r’   r™   rž   r    r¡   rª   r«   r¯   r°   r±   r²   r   rl   r»  r¶   r·   ÚdecimalÚDecimalr¸   r¹   r<   rG   r9   rÂ   rÎ   rÏ   rÕ   rØ   r   rÝ   rÞ   ÚOPTIONAL_READ_WRITE_FIELDr   r+   rê   rë   rð   rñ   rò   ró   ÚALL_DOCUMENT_PERMISSIONSrô  r4   r  r   r  r   r   r   rv   r  r  r  r3  r4  r7   r8   r=   r?   rA   rC   rB   r  r<  rC  rD  rH   rG  rI  rH  rJ  rL  rM  rS  rT  rW  r"   rP   r^  r_  rb  r5   r>   rk  rN   rS   rr  rw  ry  r|  r~  r  r€  r�  rƒ  r„  r§  r©  r«  r¬  rE   r¶  r·  r¸  rÃ  rÊ  rO   rÅ  rÇ  rÍ  rÏ  rÐ  rÈ  rÑ  rØ  rR   rÔ  rÖ  rÙ  rÛ  r×  rÜ  rÂ  rê  r   r   rñ  rK   r�   rL   rõ  r	  r   r  r  r   rþ  r  rÿ  r   rQ   r  r  r  rn   rn   rn   ro   rT   …   sÈ  (
û

	 ýü
þüû"ýüýü üû üûÿþ		ÿþÿþ  üû  üûþ"	Sþýüýüü
ûEü
ûýüýüùø^ 	÷ÿòQ&		#   ûú(ý
üÿþ üûÿþÿþöõP    øö    øöþ ýüþ üû*þ		Nÿþ-ÿþ úùPûú úø$ úø
	!						þ)   ö$ÿ"ÿõ5   ùø 
û;

û
û
ú5
û ü
ûý

üý

üÿþrT   r|   c                 C   sÌ   t | tƒr| S t | tƒrLtƒ }|  ¡ D ] \}}t|ƒ}t|ƒ}|||< q&|S t | tƒrxtƒ }| D ]}| 	t|ƒ¡ q`|S t | t
ƒrž|  d¡r”t| ƒS t| ƒS n*t | ttfƒr´t| ƒS tdt| ƒ› d�ƒ‚d S )Nri  z
type(obj)=z! could not be casted to PdfObject)r‰   rD   rä  r=   r0  rA   râ  r“   r7   r�   r’   Ú
startswithrG   rŠ   r»  r?   rx  Útype)r}   rå  r  r2  Zname_keyZcasted_valuer  Úelrn   rn   ro   râ  Ã
  s.    






ÿrâ  )r]  rc  rd  rf  re  rW   c                    s²   t ƒ }| d ur| |tdƒ< | tdƒt|ƒi¡ |rtt|tƒrFt|ƒ}t d¡‰ | tdƒt	‡ fdd„|D ƒƒi¡ |s||r®d}|rŒ|d7 }|r˜|d	7 }| td
ƒt
|ƒi¡ |S )NrZ  r}  z1.00000r  c                    s    g | ]}t t |¡ ˆ ¡ƒ‘qS rn   )r?   r%  r&  Úquantize)r7  Úc©Úprecrn   ro   r8  õ
  r¨   z(_create_outline_item.<locals>.<listcomp>r   r   r»   rÒ   )rH   rA   r\   rI   r‰   r’   rJ   r%  r&  r7   rC   )r]  rc  rd  rf  re  rX  Zformat_flagrn   r.  ro   ro  ß
  s2    ÿÿ

ÿÿÿro  c                       s&   e Zd Zeeddœ‡ fdd„Z‡  ZS )ÚPdfFileWriterN)r1  ÚkwargsrW   c                    s"   t dddƒ tƒ j|i |¤Ž d S )Nr0  rT   rŽ   )r#   Úsuperrp   )rk   r1  r1  ©r@  rn   ro   rp     s    zPdfFileWriter.__init__)rä   r  r   r	   rp   Ú__classcell__rn   rn   r3  ro   r0    s   r0  )|rc   r9  r%  Úloggingr  r  r&  r  rË   r†   Úhashlibr   Úior   r   r   Úpathlibr   Útypesr   Útypingr   r	   r
   r   r   r   r   r   r   r   r   r   r   rî  r   Z_pager   r   Z_readerr   Z	_securityr   r   r   Ú_utilsr   r   r   r    r!   r"   r#   r$   Ú	constantsr%   r&   rÉ   r'   r(   rh   r)   r  r*   r+   r,   r-   r.   r/   râ   r0   r]   r1   r  r2   rí   r3   r4   Zgenericr5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   Z	pagerangerK   rL   rM   rN   rO   rP   rQ   rR   rS   Ú	getLoggerrä   rš   r'  r(  rT   r’   rŠ   râ  r»  rô  ro  r0  rn   rn   rn   ro   Ú<module>   s„   <(
`$

                    R(
ú$