403Webshell
Server IP : 93.86.61.54  /  Your IP : 216.73.216.60
Web Server : Apache/2.4.62 (Ubuntu)
System : Linux rasin.ddns.net 6.8.0-124-generic #124~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Tue May 26 21:05:19 UTC x86_64
User : www-data ( 33)
PHP Version : 8.4.22
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /lib/python3/dist-packages/reportlab/pdfbase/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /lib/python3/dist-packages/reportlab/pdfbase/__pycache__/pdfdoc.cpython-310.pyc
o

��d`�@s|dZdZddlZddlZddlZddlmZddlmZddl	m
Z
ddlmZm
Z
mZmZmZmZmZmZmZmZddlmZmZmZmZdd	lmZdd
lmZddlmZGdd
�d
e �Z!dZ"dZ#dZ$dZ%dZ&dZ'e(dd�Z)dd�Z*d�dd�Z+dd�Z,e,Z-Gdd�d�Z.Gdd�d�Z/Gd d!�d!e/�Z0Gd"d#�d#e/�Z1d$Z2d%Z3d&Z4Gd'd(�d(e/�Z5d)d*�Z6ddl7Z7e7�8d+�Z9[7d,d-�Z:d.d/�Z;Gd0d1�d1e/�Z<e=d2�e=d3�fd4d5�Z>Gd6d7�d7e/�Z?Gd8d9�d9�Z@d:d;�ZAGd<d=�d=e?�ZBGd>d?�d?eB�ZCGd@dA�dA�ZDeD�ZEGdBdC�dC�ZFeF�ZGGdDdE�dEe/�ZHd�dFdG�ZIdHZJGdIdJ�dJe/�ZKGdKdL�dLeK�ZLGdMdN�dNe/�ZMGdOdP�dPe/�ZNGdQdR�dRe/�ZOGdSdT�dTe/�ZPGdUdV�dVe/�ZQGdWdX�dXe/�ZRGdYdZ�dZe/�ZSGd[d\�d\eS�ZTGd]d^�d^eS�ZUGd_d`�d`e �ZVGdadb�dbeS�ZWGdcdd�ddeS�ZXdedf�ZYdgZZGdhdi�die/�Z[Gdjdk�dke/�Z\Gdldm�dme/�Z]d�dndo�Z^dpZ_Gdqdr�dre/�Z`Gdsdt�dte/�ZaGdudv�dvea�ZbGdwdx�dxea�ZcGdydz�dzea�ZdGd{d|�d|ed�Zed}d~�ZfGdd��d�e/�ZgGd�d��d�e/�ZhGd�d��d�e/�ZiGd�d��d�e/�ZjGd�d��d�e/�ZkGd�d��d�ek�ZlGd�d��d�e/�ZmGd�d��d�em�ZnGd�d��d�e/�ZoGd�d��d�eo�ZpGd�d��d�e/�ZqGd�d��d�e/�ZrGd�d��d�e/�ZsGd�d��d�es�ZtGd�d��d�e/�ZuGd�d��d�e/�Zvd�d�d�d��ZwGd�d��d�e/�ZxGd�d��d��ZyGd�d��d�e/�ZzGd�d��d�ez�Z{Gd�d��d�ez�Z|Gd�d��d�e/�Z}Gd�d��d�e}�Z~Gd�d��d�e}�ZGd�d��d�e}�Z�e�d�k�r�e�d��dSdS)�z3.4.1a_
The module pdfdoc.py handles the 'outer structure' of PDF documents, ensuring that
all objects are properly cross-referenced and indexed to the nearest byte.  The
'inner structure' - the page descriptions - are presumed to be generated before
each page is saved.
pdfgen.py calls this and provides a 'canvas' object to handle page marking operators.
piddlePDF calls pdfgen and offers a high-level interface.

The classes within this generally mirror structures in the PDF file
and are not part of any public interface.  Instead, canvas and font
classes are made available elsewhere for users to manipulate.
�N)�OrderedDict)�pdfutils)�	rl_config)
�
open_for_read�makeFileName�isSeq�isBytes�	isUnicode�	_digester�isStr�bytestr�annotateException�	TimeStamp)�	escapePDF�fp_str�asciiBase85Encode�asciiBase85Decode)�
pdfmetrics)�md5)�stderrc@�eZdZdS)�PDFErrorN��__name__�
__module__�__qualname__�rr�:/usr/lib/python3/dist-packages/reportlab/pdfbase/pdfdoc.pyr�r�__InternalName__�__RefOnly__�__Comment__�
BasicFonts�Pages)��)r$�)�transparencycCst|t�r
|�d�S|S)N�	extpdfdoc)�
isinstance�str�encode)�xrrr�	pdfdocEnc5sr-cCs�t|t�r/|st|t�r|�|��|�S|�|�}tjs-tjr-t|t	�r-t
d|j	�|}|St|�tt
fvr=t
t|��St|�rC|St|�rKt
|�St
t|��S)z�Indirection step for formatting.
       Ensures that document parameters alter behaviour
       of formatting for all elements.
    z%% %s
)r)�	PDFObject�hasattrr �	Reference�formatr�	invariant�pdfCommentsr!r-�type�float�intrrr	r*)�element�document�toplevel�frrrr18s

r1cCsd|S)Nz
FormXob.%sr)�externalnamerrr�xObjectNameR�r<c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�NoEncryptioncCs|S)zencode a string, stream, textr)�self�trrrr+Z�zNoEncryption.encodecC�dS�Nr�r?r8rrr�prepare]rAzNoEncryption.preparecCrBrCr)r?�objnum�versionrrr�register`rAzNoEncryption.registercCrBrCr�r?rrr�infocrAzNoEncryption.infoN)rrrr+rErHrJrrrrr>Ys
r>c@r)r.Nrrrrrr.grr.c@seZdZdZe�ZdS)�DummyDocz'used to bypass encryption when requiredN)rrr�__doc__r>�encryptrrrrrKjs
rKc@s4eZdZdZe�Zdejejde	dfdd�Z
dd�Zdd�Zd	d
�Z
dd�Zd
d�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Z d1d2�Z!d3d4�Z"d5d6�Z#d7d8�Z$d9d:�Z%d;d<�Z&dFd>d?�Z'd@dA�Z(dBdC�Z)dGdDdE�Z*dS)H�PDFDocumentNrcCs.d|_d|_d|_d|_d|_|durtj|_n||_|�|�||_t	�}|_
|�d�t|j�|_
|j
j}t|�}|�t|��i|_i|_i|_i|_t�}|_|_t�}	|_|	|_|re|ntj}|rot|�|_|rtt�nt�|_|_ |_ t!�|_"i|_#t$i�}
d|
_%|�&|
t'�g|_(dS)Nrr$sa reportlab documentzThe standard fonts dictionary))�_ID�
objectcounter�shadingCounter�inObject�pageCounterrr2�setCompression�_pdfVersionr�	signature�updater�
_timeStampr@�asciir�idToObjectNumberAndVersion�
idToObject�
idToOffset�
numberToId�
PDFCatalog�Catalog�_catalog�PDFPagesr#�documentLang�	PDFString�Lang�PDFOutlines0�PDFOutlines�outline�Outlines�PDFInforJ�fontMapping�
PDFDictionaryr!r0r"�delayedFonts)r?�dummyoutline�compressionr2�filename�
pdfVersion�lang�sig�cat�pages�DDrrr�__init__ssB




zPDFDocument.__init__cC�
||_dSrC�rn�r?�onoffrrrrT�s
zPDFDocument.setCompressioncGs |D]}t|jt|�|_qdS)zREnsure that the pdf version is greater than or equal to that specified by the keysN)�maxrU�PDF_SUPPORT_VERSION)r?�keys�krrr�ensureMinPdfVersion�s�zPDFDocument.ensureMinPdfVersioncCs|jrdS|j�t|��dS)z add information to the signatureN)rOrVrWr)r?�thingrrr�updateSignature�s
zPDFDocument.updateSignaturecCsF|jr|jS|j��}t�}t|dd��|�}d||d|_|jS)z<A unique fingerprint for the file (unless in invariant mode)�raw)�encs
[sJ]
% ReportLab generated PDF document -- digest (http://www.reportlab.com)
)rOrV�digestrK�PDFTextr1)r?r��doc�IDsrrr�ID�s
zPDFDocument.IDcCs,t|dd�rtd|jj��d|_tt|dd�d�rAd}|}t|dd�}t|t�r.d	|}nt|�s<d
|jjt	|�f}t
|�}nt|�rQd}t
|�}t|d�}ntd
t
|���|�|�}t|�rg|�d�}|�|�|r�|��ddl}|jdkr�ddlm}||�t|dd�r�td|f�dSdS)N�_savedToFileFz)class %s instances can only be saved onceT�write�__call__r�namez
<os fd:%d>z<%s@0X%8.8X>r$�wbz#Cannot use %s as a filename or file�latin1�mac)�markfilename�
_verbosityzsaved %s)�getattr�RuntimeError�	__class__rr�r/r)r6r�idr�open�	TypeError�repr�
GetPDFDatar	r+r��close�osr��reportlab.lib.utilsr��print)r?ro�canvas�myfiler:�datar�r�rrr�
SaveToFile�s8






"zPDFDocument.SaveToFilecCsp|jD]}|�|�q|j|j_|j�|j�|�|j�|�|j�|j�	||�|jj
dkr4d|j_|��S�Nr)rl�
addObjectsr2rJr�rVr0r_rhrE�readyr1)r?r��fntrrrr��s

zPDFDocument.GetPDFDatacCs0|jdur|jdkrdStd|j��d|_dS)zXspecify the current object as a page (enables reference binding and other page features)N�pagez%can't go in page already in object %s)rR�
ValueErrorrIrrr�inPage�s

zPDFDocument.inPagecCs
d|_dS)zBspecify that we are in a form xobject (disable page features, etc)�formN)rRrIrrr�inForm�s
zPDFDocument.inFormcCsj|j}||vr||Szt�|�}|jrtdt|���|�|�||WSty4tdt|���w)Nz1getInternalFontName(%s) called for a dynamic fontzFont %s not known!)rjr�getFont�_dynamicFontrr�r��KeyError)r?�
psfontname�fm�fontObjrrr�getInternalFontName�s


�zPDFDocument.getInternalFontNamecCsdt|j�S)N�Page)r�rSrIrrr�thisPageName�zPDFDocument.thisPageNamecCst|���SrC)�PDFObjectReferencer�rIrrr�thisPageRef�zPDFDocument.thisPageRefcCs8|��}|�||�|j�|�|jd7_d|_dS)Nr$)r�r0r#�addPagerSrR)r?r�r�rrrr�s

zPDFDocument.addPagecCs,|jdkr	|��|�|t|��d|_dS)zadd a Form XObject.r�N)rRr�r0r<)r?r�r�rrr�addForms

zPDFDocument.addFormcCsd|S)NzAnnot.%sr)r?r;rrr�annotationName#r=zPDFDocument.annotationNamecCs|�||�|��dSrC)r0r�)r?r��
annotationrrr�
addAnnotation&�zPDFDocument.addAnnotationcCs|�|�}t|�SrC)r�r��r?r��internalnamerrr�
refAnnotation)s
zPDFDocument.refAnnotationcCs(d|j}|�||�|jd7_|S)NzSh%dr$)rQr0)r?�shadingr�rrr�
addShading-s
zPDFDocument.addShadingcCs�|j}|sZ|jdkr|jdkr|jdkrd}n5|jdkr)|jdkr)|jdkr)d}n#|jdkr;|jdkr;|jdkr;d}n|jdkrL|jdkrL|jdkrLd}|sTtd|��|j|d�}t|�dd�}||jvrst	|��
�}|�||�||fS)	Nr�BLACK�CYAN�MAGENTA�YELLOWz&CMYK colour %r used without a spotName)�spotNamer$)r��cyan�magenta�yellow�blackr��clone�PDFNamer[�PDFSeparationCMYKColor�valuer0)r?�cmyk�snamer��seprrr�addColor3s$
zPDFDocument.addColorcC� |dur
d|j_dS||j_dS)�embeds in PDF fileN�(anonymous))rJ�title)r?r�rrr�setTitleH�zPDFDocument.setTitlecCr�)zembedded in PDF fileNr�)rJ�author)r?r�rrr�	setAuthorOszPDFDocument.setAuthorcCr��r�Nz
(unspecified))rJ�subject)r?r�rrr�
setSubjectW�zPDFDocument.setSubjectcCr�r�)rJ�creator)r?r�rrr�
setCreator`r�zPDFDocument.setCreatorcCs |dur
t|j_dS||j_dS)r�N)�_default_producerrJ�producer)r?r�rrr�setProducergr�zPDFDocument.setProducercCr�)z/embeds a string containing keywords in PDF fileN�)rJ�keywords)r?r�rrr�setKeywordsnr�zPDFDocument.setKeywordscCs||j_dSrC)rJ�_dateFormatter)r?�
dateFormatterrrr�setDateFormatterwr�zPDFDocument.setDateFormattercCsDt|j���}ddlm}|jD]}||vr|�|�q|��|S)Nr)�	_fontdata)�listrjr}�reportlab.pdfbaser��
standardFonts�append�sort)r?�	fontnamesr�r�rrr�getAvailableFontszs

�zPDFDocument.getAvailableFontscCs�|j�|�|j}|j}|�|�|�|�d}|j��}|r$|�|�}d}g}|j}|j}|j}	|j}
t	|j
�|_}	|d7}||vrFnE||}|	|}
t||
�}|�
|�}tjs|tjr|z|
jj}Wnt|
�}Y|�dt|�|dd�f�|�|�}||
|<|�|�q=|`t|�}|d|kr�td||f��t�}|�d|�|�
|�}|�|�}t||d|�|�|�|�||��d�}|�
|�}|�|�t|dg�D]}|�|�q�|�
|�S)	NrTr$z%% %s: class %s 
�2z3counter %s doesn't match number to id dictionary %s)�	startxref�Size�Root�Info�Encryptr��	_digiSigs)rMrEr_rJr0r]rZr[r\�PDFFilerU�	__accum__�PDFIndirectObjectr1rr2r3r�rrY�addr��lenr��PDFCrossReferenceTable�
addsection�
PDFTrailerr�r��sign)r?rsrJ�
encryptref�encryptinfo�counter�ids�
numbertoid�idToNV�idToOb�idToOf�File�oid�obj�IO�IOf�	classname�offset�lno�xref�xreff�
xrefoffset�trailer�trailerf�dsrrrr1�sl









�

�


zPDFDocument.formatcCst|�}||jvS)z test for existence of named form)r<r[r�rrr�hasForm�s
zPDFDocument.hasForm�MediaBoxcCsrt|�}||jvr7|j|}t|d�r|j|St|t�r!|��St|t�r/t|j	j
|j�Stdt
|���dS)z�get the declared bounding box of the form as a list.
        If you specify a different PDF box definition (e.g. the
        ArtBox) and it has one, that's what you'll get.�_extra_pageCatcher_infoz'I don't understand the form instance %sN)r<r[r/rr)�PDFFormXObject�BBoxList�	PDFStreamr��
dictionary�dict�sequencer�r�)r?r��boxTyper��theformrrr�getFormBBox�s





�zPDFDocument.getFormBBoxcC�t|�S)ziLets canvas find out what form is called internally.
        Never mind whether it is defined yet or not.)r<�r?r�rrr�getXObjectName�szPDFDocument.getXObjectNamecCs.i}|D]}t|�}t|�}|||<qt|�S)z�construct an xobject dict (for inclusion in a resource dict, usually)
           from a list of form names (images not yet supported))r<r�rk)r?�	formnames�Dr�r��	referencerrr�xobjDict�s
zPDFDocument.xobjDictcCst|t�}|j}|dur|r|jtur|St|t�rE|j}|dur1||kr1tdt|�t|�f��||vrAtdt	|�t
|�f��t|�S|jd}|_|durWdt|�}||vro||}||krktdt|���t|�S|rt||_|df|j|<||j
|<|||<t|�S)Nz0attempt to reregister object %s with new name %sz1object of type %s named as %s, but not registeredr$�Rzredefining named object: r)r)r.r[r�r�r/rr�r�r4rYrPrZr])r?r
r��iobr[�intnamerP�otherrrrr0�s6

�
zPDFDocument.Reference)rrC)+rrr�defaultStreamFiltersr>rMr�pageCompressionr2�PDF_VERSION_DEFAULTrvrTrr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r1rr$r'r+r0rrrrrNosT
�5
 		
E
rN�true�false�nullc@s&eZdZd	dd�Zdd�Zdd�ZdS)
r��utf-8cC�||_||_dSrC)r@r�)r?r@r�rrrrv�
zPDFText.__init__cCs8|j}t|�r
|�|j�}t�|j�|��}d|dS)N�<�>)r@r	r+r��binascii�hexlifyrM)r?r8r@�resultrrrr1s
zPDFText.formatcCst�}|�|�SrC)rKr1)r?�dummydocrrr�__str__ r8zPDFText.__str__N)r6)rrrrvr1r?rrrrr�s
r�cCs|SrCr)�nrrr�	PDFnumber$�rAz[^()]cCsPt�d|�}d}|D]}|dkr|d7}q
|d8}|dkr dSq
|r&dp'dS)z+test whether a string is balanced in parensr�r�(r$)�_re_cleanparens�sub)�sr@�crrr�_isbalanced*srHc
Cs8z|�d�WdSty}zWYd}~dSd}~ww)z(return true if no Pdfdoc encoding errors�pdfdocr$Nr)r+�UnicodeEncodeError)�utext�errr�_checkPdfdoc5s
��rMc@s*eZdZdZddd�Zdd�Zdd	�Zd
S)rcFr$�autocCs<t|t�r|j|_|j|_|j|_dS||_||_||_dS)azs can be unicode/utf8 or a PDFString
        if escape is true then the output will be passed through escape
        if enc is raw then bytes will be left alone
        if enc is auto we'll try and automatically adapt to utf_16_be/utf_16_le if the
        effective string is not entirely in pdfdoc
        if self.unicodeEncValid unicode will use the specifed encoding
        N)r)rcrF�escaper�)r?rFrOr�rrrrv?s

zPDFString.__init__cCs�|j}t|dd�}t|�r_|dkr^z1|�tj�r|�d�}n|�tj�r*|�d�}n|�d�}t|�r9|�	d�}ntj|�	d�}WnRz|�d�Wnt
�dt|�f��Yn7n6t
|�r�|dkrzt|�rq|�	d�}n$tj|�	d�}n|jr�|�	|j�}ntj|�	d�}ntdt|���t|d	d
�}t|jt�s�|j�	|�}d
}|r�zdt|�}Wn
td|t|�f��|d
@r�|�dd�}|d@r�t|�r�|�dd��dd�}t|�Sd|dS)Nr�rN�	utf_16_be�	utf_16_le�utf8rIzError in %sz-PDFString argument must be str/unicode not %srOr$�(%s)zcannot escape %s %s�z\012�
r&z\(rCz\)�)�(�))rFr�r�
startswith�codecs�BOM_UTF16_BE�decode�BOM_UTF16_LErMr+rr�r�r	�unicodeEncValidr�r�r4r)rMr>r�replacerHr-)r?r8rFr��urO�esrrrr1Os\
���zPDFString.formatcCsdt|j�S)NrS)rrFrIrrrr?�r�zPDFString.__str__N)r$rN)rrrr^rvr1r?rrrrrc=s

4rc�!�~cCs\t|�}t|�D]\}}||ks||ks|dvr&dtt|��dd�||<qdd�|�S)Nz
%()<>{}[]#�#rT�/r�)r��	enumerate�hex�ord�join)r��lo�hi�L�irGrrrr��s�r�c@sTeZdZdZddd�Zdd�Zdd�Zd	d
�Zdd�Zddd�Z	dd�Z
dd�ZdS)rkTNcCs |dur	i|_dS|��|_dS)zPdict should be namestring to value eg "a": 122 NOT pdfname to value NOT "/a":122N)r �copy)r?r rrrrv�s
zPDFDictionary.__init__cCs||j|<dSrC�r )r?r�r�rrr�__setitem__�r�zPDFDictionary.__setitem__cC�
|j|SrCro�r?�arrr�__getitem__��
zPDFDictionary.__getitem__cCs
||jvSrCrorrrrr�__contains__�ruzPDFDictionary.__contains__cCs|�|j|�|j|<dSrC)r0r )r?r�r8rrrr0�szPDFDictionary.Reference�
 cs�|j�zt����}Wn
tt����t�t�s|����fdd�|D�}|jr/t	j
s4|jdkr:|�|�}n|j}t
tdt|�d��D]}||d�qGd�|�}d|dS)	Ncs,g|]}tt|���dt�|���qS)� )r1r���.0r~�r r8rr�
<listcomp>�s,z(PDFDictionary.format.<locals>.<listcomp>�forced�rwrxs<<
s
>>)r r�r}r�rYr)rr��	multiliner�pdfMultiLineri�insert�reversed�ranger�)r?r8�INDr}rlr@rmrr{rr1�s
zPDFDictionary.formatcC�
t|j�SrC)rkr rIrrrrn�ruzPDFDictionary.copycCs<|j}dd�|��D�}|D]
}|�|�||dd�<qdS)NcSsg|]	}|�d�r|�qS)re)rYryrrrr|�sz+PDFDictionary.normalize.<locals>.<listcomp>r$)r r}�pop)r?r)�Kr~rrr�	normalize�s
�zPDFDictionary.normalizerC�rw)rrrrrvrprtrvr0r1rnr�rrrrrk�s

rkc@�eZdZdd�Zdd�ZdS)�
checkPDFNamescGsttt|��|_dSrC)r��mapr��names)r?r�rrrrv��zcheckPDFNames.__init__cCs$|�d�s	t|�}||jvr|SdS)Nre)rYr�r�)r?r�rrrr��s


�zcheckPDFNames.__call__N)rrrrvr�rrrrr���r�cCs|dvr|SdS)N)r3r4r)r�rrr�checkPDFBoolean��r�c@s"eZdZiZddd�Zdd�ZdS)�CheckedPDFDictionaryNcCst�||�|r
||_dSdSrC)rkrv�validate)r?r r�rrrrv�szCheckedPDFDictionary.__init__cCsN||jvrtd|��|j||�}|durtd||f��t�|||�dS)Nzinvalid key, %rzBad value %r for key %r)r�r�rkrp)r?r�r��cvaluerrrrp�s
z CheckedPDFDictionary.__setitem__�NN)rrrr�rvrprrrrr��s
r�c@speZdZeeeeeeeed���ed���ed���ed���ed���ed���ed���ed���d�ZdS)�ViewerPreferencesPDFDictionaryz#UseNone UseOutlines UseThumbs UseOCzL2R R2Lz(MediaBox CropBox BleedBox TrimBox ArtBoxzNone AppDefaultz.Simplex DuplexFlipShortEdge DuplexFlipLongEdge)�HideToolbar�HideMenubar�HideWindowUI�	FitWindow�CenterWindow�DisplayDocTitle�NonFullScreenPageMode�	Direction�ViewArea�ViewClip�	PrintArea�	PrintClip�PrintScaling�DuplexN)rrrr r�r��splitr�rrrrr��s"








�r�c@� eZdZdZdd�Zdd�ZdS)�PDFStreamFilterZCompress�FlateDecodecCst|�r	|�d�}t�|�S)NrR)r	r+�zlib�compress�r?�textrrrr+�s

zPDFStreamFilterZCompress.encodecCs
t�|�SrC)r��
decompress)r?�encodedrrrr\�ruzPDFStreamFilterZCompress.decodeN�rrr�pdfnamer+r\rrrrr��sr�c@r�)�PDFStreamFilterBase85Encode�
ASCII85DecodecCs&ddlm}t|�}tjr||�}|S)Nr)�_wrap)�reportlab.pdfbase.pdfutilsr�rr�wrapA85)r?r�r�rrrr+�s
z"PDFStreamFilterBase85Encode.encodecCr%rC)rr�rrrr\�r=z"PDFStreamFilterBase85Encode.decodeNr�rrrrr��sr�c@s&eZdZdZdZddd�Zdd�ZdS)	rz@set dictionary elements explicitly stream.dictionary[name]=valuer$NcCs$|durt�}||_||_||_dSrC)rkr�content�filters)r?rr�r�rrrrv	s

zPDFStream.__init__c
Cs�|j}t|j���}|j}|j}|jdurtd��|dur |j}|durLd|jvrLt|�}|�	�g}|D]}|�
|�}|�dt|j
��q5t|�|d<|j�
|�}t||�}t|�|d<t||�}	|	d|dS)Nzstream content not set�Filterr�Lengths
stream
s
endstream
)rrkr rnr�r�r�r0r��reverser+r�r�r��PDFArrayrMr1r�)
r?r8rr�r��rf�fnamesr:�fc�fdrrrr1s*



zPDFStream.format�NNN)rrrrLr rvr1rrrrrs

rcCs>|durt}|��d}t|tjrttgptgd�}d|_|S)NrU)r�r�ztest stream)�teststreamcontent�striprr�useA85�PDFBase85Encode�PDFZCompressr!)r��Srrr�
teststream/s�r�z\
1 0 0 1 0 0 cm BT /F9 12 Tf 14.4 TL ET
1.00 0.00 1.00 rg
n 72.00 72.00 432.00 648.00 re B*
c@s*eZdZdZdd�Zdd�Zd
dd�Zd	S)r�TcC�t|�|_dSrC)r�r!)r?r!rrrrvAr�zPDFArray.__init__cCstt|j|j��|_dS)z'make all objects in sequence referencesN)r�r�r0r!rDrrr�
ReferencesCszPDFArray.Referencesrwcs��fdd�|jD�}|jrtjs|jdkr|�|�}n&t|�}|dkr<|j}ttd|d��D]}||d�q.d�|�}nd�|�}d|dS)	Ncsg|]}t|���qSr)r1)rzrL�r8rrr|G�z#PDFArray.format.<locals>.<listcomp>r}�
rwrxs[ s ])	r!rrr�rir�r�r�r�)r?r8r�rlr@r@rmrr�rr1Fs
zPDFArray.formatNr�)rrrrrvr�r1rrrrr�?s
r�c@�eZdZdZdS)�PDFArrayCompactFN)rrrrrrrrr�V�r�c@r�)r�r$cCr7rC)r�r�)r?r�r�rrrrv[r8zPDFIndirectObject.__init__cCsb|j}|j|\}}|j�||�t|j|dd�}td||f�||�d�r,ddSddS)Nr$�r9z
%s %s obj
�
�sendobj
)r�rZrMrHr1r�r-�endswith)r?r8r�r@�v�fcontentrrrr1^s�����zPDFIndirectObject.formatN)rrrr rvr1rrrrr�Ysr�c@r�)r�cCrwrC)r�r&rrrrviruzPDFObjectReference.__init__cCs0ztd|j|j�WStdt|j���)Nz%s %s Rz:forward reference to %s not resolved upon final formatting)r-rZr�r�r�rDrrrr1kszPDFObjectReference.formatN�rrrrvr1rrrrr�hr�r�c@s0eZdZefdd�Zdd�Zdd�Zdd�Zd	S)
r�cCs0g|_|jj|_d|_|�td|�d�dS)Nrz%%PDF-%s.%ssA
%���� ReportLab Generated PDF document http://www.reportlab.com
)�stringsr�r�rr�r-)r?rprrrrvss

�zPDFFile.__init__cCrBrCrrIrrr�closeOrReset�rBzPDFFile.closeOrResetcCs*t|�}|j}|t|�|_|�|�|S)zGshould be constructed as late as possible, return position where placed)r-rr�r�)r?rFr=rrrr��s

zPDFFile.addcCsd�|j�S)Nr�)rir�rDrrrr1�r�zPDFFile.formatN)rrrr2rvr�r�r1rrrrr�qs
r�c@r�)�PDFCrossReferenceSubsectioncCr7rC)�firstentrynumber�
idsequence)r?r�r�rrrrv�r8z$PDFCrossReferenceSubsection.__init__cCs|j}|j}t|�}t|�}i}|dkr"d|d<|d}|�dd�|j}|j}||d}	|D]@}
||
\}}||vrKtd|t|
�t||
�f��||	ksS||kr\td|||	f��||}
|
||<||
}d||f||<q0d||f}|�d|�|�	d	�t
d
�|��S)z`id sequence should represent contiguous object nums else error. free numbers not supported (yet)rzstandard free entryr$z0000000000 65535 f z object number collision %s %s %sz$object number %s not in range %s..%sz%0.10d %0.5d n z%s %sr�rU)r�r�r�r�r�rZr\r�r�r�r-ri)r?r8r�r��entries�nentries�takenrr\�lastentrynumberr��numrG�rnumr�	firstlinerrrr1�s4
z"PDFCrossReferenceSubsection.formatNr�rrrrr��sr�c@�$eZdZdd�Zdd�Zdd�ZdS)r�cC�
g|_dSrC)�sectionsrIrrrrv�ruzPDFCrossReferenceTable.__init__cCst||�}|j�|�dSrC)r�r�r�)r?�
firstentryr�sectionrrrr�s
z!PDFCrossReferenceTable.addsectioncCsF|j}|s	td��dg}|jD]}t||�}|�|�qtd�|��S)Nzno crossref sectionssxref
r�)r�r�r1r�r-ri)r?r8r�rlrF�fsrrrr1�s

zPDFCrossReferenceTable.formatN)rrrrvrr1rrrrr��sr�c@seZdZddd�Zdd�ZdS)rNcCsv||_|dus|durtd��t�}|_d|fd|fd|fd|fd|fd|ffD]\}	}
|
dur5|
||	<q)d|_dS)	NzSize and Root keys requiredr��Prevr�r�r�r�r})r�r�rkr r)r?r�r�r�r�r�r�r�r r@r�rrrrv�s��
zPDFTrailer.__init__cCs.|jj|dd�}d�d|dtt|j��dg�S)Nr��r�r�strailer
s
startxref
s
%%EOF
)r r1rir-r*r�)r?r8�fdictrrrr1�s�zPDFTrailer.format)NNNNNNr�rrrrr�s

rc@sdeZdZdZdZed�ed�dd�Zd��ZeZ	dd	�Z
d
d�Zdd
�Zdd�Z
dd�Zdd�ZdS)r^z
Document Rootr$r_�UseNoneN)�Type�PageModerdz�
        Dests Outlines Pages Threads AcroForm Names OpenAction PageMode URI
        ViewerPreferences PageLabels PageLayout JavaScript StructTreeRoot SpiderInfocCs�|�|�|j}|j}i}|��D]\}}t|||�}|dur#|||<q|jD]}t||d�}|dur7|||<q'|D]}||vrI|�||�||<q:t|�}t||�SrC)	�check_format�__Defaults__�__Refs__�itemsr��
__NoDefault__r0rkr1)r?r8�defaults�Refsr)r~r�r rrrr1�s(
�
��
zPDFCatalog.formatcC�|�d�dS)N�UseOutlines��setPageModerIrrr�showOutliner�zPDFCatalog.showOutlinecCr�)N�
FullScreenr�rIrrr�showFullScreenr�zPDFCatalog.showFullScreencC�|r	t|�|_dSdSrC)r��
PageLayout)r?�layoutrrr�
setPageLayout��zPDFCatalog.setPageLayoutcCr�rC)r�r�)r?�moderrrr�rzPDFCatalog.setPageModecC�dS)zfor use in subclassesNrrDrrrr�rAzPDFCatalog.check_format)rrrr!r r�r�r�r�r�r1r�r�rr�r�rrrrr^�s"��r^c@sReZdZdZdZdZded�iZd��Z	dgZ
dd	�Zd
d�Zdd
�Z
dd�ZdS)razHPAGES TREE WITH ONE INTERNAL NODE, FOR "BALANCING" CHANGE IMPLEMENTATIONz	page treer$r�r#zKids Count Parent�ParentcCr�rC�rtrIrrrrvruzPDFPages.__init__cCrqrCr)r?�itemrrrrtruzPDFPages.__getitem__cCs|j�|�dSrC)rtr��r?r�rrrr� r�zPDFPages.addPagecCs,|j}t|�}|�|�||_t|�|_dSrC)rtr�r��Kidsr��Count)r?r8rt�kidsrrrr�"s

zPDFPages.check_formatN)rrrrLr!r r�r�r�r�r�rvrtr�r�rrrrrasrac@s�eZdZdZdZdZded�iZd��Z	d��Z
dZd	Zd
Z
dZdZd
ZiZiZd
Zdd�Zd
d�Zdd�Zdd�Zdd�Zd
S)�PDFPagezPage dictionaryrr$r�r�z�Parent
        MediaBox Resources Contents CropBox Rotate Thumb Annots B Dur Hid Trans AA
        PieceInfo LastModified SeparationInfo ArtBox TrimBox BleedBox ID PZ
        TranszContents Parent ID�SiJNcCs|jD]}t||d�qdSrC)r��setattrr&rrrrvEs
�zPDFPage.__init__cCrwrCrxryrrrrTIruzPDFPage.setCompressioncCs.|jrtd��t|�rd�|�d}||_dS)Nz&overridden! must set stream explicitlyrU)�Override_default_compilationr�rri�stream)r?�coderrr�	setStreamKs

zPDFPage.setStreamcCr�rC)rk�Trans)r?�tranDictrrr�setPageTransitionRr�zPDFPage.setPageTransitioncCs:|jrdS|jpt|jdvrdd|j|jgpdd|j|jg�|_|js'd|_nt|jt�s3t|j�|_|j	sZ|j
}|s@t�|_	nt�}|j
rQtjrMttgpOtg|_||_d|_||_	|js�t�}|��|jrl|��n|��|jrw|j|_|jr~|j|_|�|j�|� |j!�||_|j"s�|j#}|�$|�|_"dSdS)N)�Zirzpage stream)%rrr��Rotate�
pageheight�	pagewidth�Annotsr)r.�Contentsrr�rrnrr�r�r�r�r�r!�	Resources�PDFResourceDictionary�
basicFonts�	hasImages�allProcs�
basicProcs�XObjects�XObject�	ExtGState�
setShading�_shadingUsed�
setColorSpace�_colorsUsedrr#r0)r?r8rr��	resourcesrtrrrr�UsD6

�zPDFPage.check_format)rrrr!rr r�r�r�r�r�rrrrrnr!r'�
_shadingsUsedrrvrTrrr�rrrrr+s.�rc@r)�DuplicatePageLabelPageNrrrrrr*�rr*c@s:eZdZdZdZiZdgZgZdd�Zdd�Z	dd	�Z
dS)
�
PDFPageLabelsNr�NumscCr�rC)�labelsrIrrrrv�ruzPDFPageLabels.__init__cCs|j�||f�dS)a� Adds a new PDFPageLabel to this catalog.
        The 'page' argument, an integer, is the page number in the PDF document
        with which the 'label' should be associated. Page numbering in the PDF
        starts at zero! Thus, to change the label on the first page, '0' should be
        provided as an argument, and to change the 6th page, '5' should be provided
        as the argument.

        The 'label' argument should be a PDFPageLabel instance, which describes the
        format of the labels starting on page 'page' in the PDF and continuing
        until the next encounter of a PDFPageLabel.

        The order in which labels are added is not important.
        N)r-r�)r?r��labelrrr�addPageLabel�szPDFPageLabels.addPageLabelc
s�z|j��Wn$ty+tdd�|jD���tdtt�fdd��D����Ynwg}|jD]\}}|�|�|�|�q1t|�|_	t
�||�S)NcSsg|]}|d�qS�rr�rzr,rrrr|��z(PDFPageLabels.format.<locals>.<listcomp>z-

!!!!! Duplicate PageLabel seen for pages %rcsg|]}��|�dkr|�qS�r$)�countr1��tmprrr|�s)r-r�r*�sortedr
r��setr�r�r,r^r1)r?r8r-r�r.rr5rr1�s&�

zPDFPageLabels.format)rrr�__comment__r r�r�r�rvr/r1rrrrr+�sr+c@sJeZdZdZdZiZd��ZdZdZ	dZ
dZdZd	Z
dd
d�Zdd
�ZdS)�PDFPageLabelNrzType S P Stz:ARABIC ROMAN_UPPER ROMAN_LOWER LETTERS_UPPER LETTERS_LOWERr)r,�r�ArscCsN|r|��|jvrt||���}t|�|_|rt|�|_|r%t|�|_dSdS)a+
        A PDFPageLabel changes the style of page numbering as displayed in a PDF
        viewer. PDF page labels have nothing to do with 'physical' page numbers
        printed on a canvas, but instead influence the 'logical' page numbers
        displayed by PDF viewers. However, when using roman numerals (i, ii,
        iii...) or page prefixes for appendecies (A.1, A.2...) on the physical
        pages PDF page labels are necessary to change the logical page numbers
        displayed by the PDF viewer to match up with the physical numbers. A
        PDFPageLabel changes the properties of numbering at the page on which it
        appears (see the class 'PDFPageLabels' for specifying where a PDFPageLabel
        is associated) and all subsequent pages, until a new PDFPageLabel is
        encountered.

        The arguments to this initialiser determine the properties of all
        subsequent page labels. 'style' determines the numberings style, arabic,
        roman, letters; 'start' specifies the starting number; and 'prefix' any
        prefix to be applied to the page numbers. All these arguments can be left
        out or set to None.

        * style:

            - None:                       No numbering, can be used to display the prefix only.
            - PDFPageLabel.ARABIC:        Use arabic numbers: 1, 2, 3, 4...
            - PDFPageLabel.ROMAN_UPPER:   Use upper case roman numerals: I, II, III...
            - PDFPageLabel.ROMAN_LOWER:   Use lower case roman numerals: i, ii, iii...
            - PDFPageLabel.LETTERS_UPPER: Use upper case letters: A, B, C, D...
            - PDFPageLabel.LETTERS_LOWER: Use lower case letters: a, b, c, d...

        * start:

            -   An integer specifying the starting number for this PDFPageLabel. This
                can be used when numbering style changes to reset the page number back
                to one, ie from roman to arabic, or from arabic to appendecies. Can be
                any positive integer or None. I'm not sure what the effect of
                specifying None is, probably that page numbering continues with the
                current sequence, I'd have to check the spec to clarify though.

        * prefix:

            -   A string which is prefixed to the page numbers. Can be used to display
                appendecies in the format: A.1, A.2, ..., B.1, B.2, ... where a
                PDFPageLabel is used to set the properties for the first page of each
                appendix to restart the page numbering at one and set the prefix to the
                appropriate letter for current appendix. The prefix can also be used to
                display text only, if the 'style' is set to None. This can be used to
                display strings such as 'Front', 'Back', or 'Cover' for the covers on
                books.

        N)	�upper�__convertible__r�r�r�rA�Strc�P)r?�style�start�prefixrrrrv�s
2
zPDFPageLabel.__init__cCstjrt��dS)NF)r�errorOnDuplicatePageLabelPager*)r?�othrrr�__lt__�szPDFPageLabel.__lt__r�)rrrr!r r�r�r�r>�ARABIC�ROMAN_UPPER�ROMAN_LOWER�
LETTERS_UPPER�
LETTERS_LOWERrvrFrrrrr:�s
8r:cCsXt�}t�|_|j}|�|�|_tgd��|_t�}|�	�|�
�||_|�|�dS)N)rrriI)
rr�rr#r0rr�rrrrrr�)r8r@rtr(rrr�testpage�srLz/
<<
  /Count
      0
  /Type
      /Outlines
>>c@s(eZdZdZe�dd�ZdZdd�ZdS)rez
TEST OUTLINE!rUr$cCr�rC)r-r�rDrrrr1ruzPDFOutlines0.formatN)	rrrr!�DUMMYOUTLINEr_r�r r1rrrrres
rec@s8eZdZdZdZZZZZZ	Z
Zdd�ZdS)�OutlineEntryObjectzan entry in an outlineNcCs\i}t|j�|d<|j|d<|j|d<dD]}t||�}|dur$|||<qt|�}|�|�S)N�Titler�Dest)r��Next�First�Lastr	)rcrOrrPr�rkr1)r?r8r)r@r��PDrrrr1s


�
zOutlineEntryObject.format)
rrrrLrOrPrr�rQrRrSr	r1rrrrrNs rNc@sleZdZdZdZZdZdZdd�Zddd�Z	d	d
�Z
dd�Zd
d�Zdd�Z
dd�Zdd�Zddd�ZdS)rfa�
    takes a recursive list of outline destinations like::

        out = PDFOutline1()
        out.setNames(canvas, # requires canvas for name resolution
        "chapter1dest",
        ("chapter2dest",
        ["chapter2section1dest",
        "chapter2section2dest",
        "chapter2conclusiondest"]
        ), # end of chapter2 description
        "chapter3dest",
        ("chapter4dest", ["c4s1", "c4s2"])
        )

    Higher layers may build this structure incrementally. KISS at base level.
    Nr���cCs"i|_i|_g|_g|_i|_dSrC)�destinationnamestotitles�destinationstotitles�
levelstack�	buildtree�	closedictrIrrrrv:�

zPDFOutlines.__init__c
CsF|dur|dkrtd��t|t�stdt|���|dkr!td��|dur'|}|j}|j}|j}||krO||dkrDtd||||f��|d}}|�g�||kr�|d}|d=|d}	|	d}
t|
t�rs|
\}}td	t	|
���|
}|}||f|	d<|d}||ksS|dur�dS|d�|�||j
|<|r�d|j|<||_dS)
z/destinationname of None means "close the tree" Nrzclose tree must have level of 0zlevel must be integer, got %sznegative levels not allowedr$z_can't jump from outline level %s to level %s, need intermediates (destinationname=%r, title=%r)rUz cannot reset existing sections: )r�r)r6r4�currentlevelrXrYr��tupler�rVrZ)
r?�destinationname�levelr��closedr\�stack�tree�current�previous�lastinpreviousr��sectionlistrrr�addOutlineEntryAs>

�

zPDFOutlines.addOutlineEntrycCrwrC)�mydestinations)r?�destinationtreerrr�setDestinationsfruzPDFOutlines.setDestinationscCs@i}td�|d<|j|d<|j|d<|j|d<t|�}|�|�S)Nrhr�r	rRrS)r�r4�first�lastrkr1�r?r8r)rTrrrr1is



zPDFOutlines.formatcGs|�||�}|�|�dSrC��translateNamesrj�r?r��nametree�desttreerrr�setNamessszPDFOutlines.setNamescCs|�||�}|�|�dS)z1Explicit list so I don't need to do in the callerNrnrprrr�setNameListwszPDFOutlines.setNameListc
Cs�|j}|j}|j}t|�r=t|�s|�d�}|�|�}|}||vr&||}n|||<|||<||vr6d||<||�|�iSt|�r\g}|D]}	|�|�	||	��qEt
|t�rZt|�S|Stdt
|���)z=recursively translate tree of names into tree of destinationsrRr$z5in outline, destination name must be string: got a %s)rVrWrZrr	r\�_bookmarkReferencerr�ror)r]r�r4)
r?r��objectrVrWrZ�destinationr�rl�orrrro|s,


zPDFOutlines.translateNamescCs�|jdur(|jr|�d�|jd}|�||�|_nd|_|_d|_d|_dSt|j|j�|_|j	||jdd�\|_|_d|_dS)zPprepare all data structures required for save operation (create related objects)NrrUr$r�)
rhrXrgrorkrlr4r�rZ�maketree)r?r8r��	destnamesrrrrE�s



zPDFOutlines.preparecCs�|rd}|�|j�}n|jd7_d|j}|durtd��t|�s'td��t|�}|d}d}}	}
|j}|j}t|�D]�}
t	�}||_
d||
f}|�||�}|dur]||_|
|_|	durc|}	|}
|}|}
||
}t
|t�ru|}n1t
|t�r�z|\}}Wntdt|���t||�|_|�|||�\|_|_ntdt|���zt|���\\}}Wntd	t|���|||_||_t
|t�r�||vr�|j|_q?|	|
fS)
N�Outliner$z
Outline.%sz2non-top level outline elt parent must be specifiedz-destinationtree must be list or tuple, got %sz%s.%sz7destination tree elt tuple should have two elts, got %sz4destination tree elt should be dict or tuple, got %sz3bad outline leaf dictionary, should have one entry )r0rhr4r�rr�rVrZr�rNrrQr�r)r r]r	ryrRrSr4r�r�rrOrP)r?r8rirr9�	levelname�nelts�	lastindex�lastelt�firstref�lastrefrVrZ�index�eltobj�eltname�eltref�elt�leafdict�subsectionsrOrPrrrry�s`




�zPDFOutlines.maketree)rNNr�)rrrrLrhr�rr\rvrgrjr1rsrtrorEryrrrrrf"s
%
rfcCsft|t�r|\}}t|���\\}}|r||vrdSt|�r1g}|D]
}|�t||��q"t|�SdS)zButility for outline: recursively count leaves in a tuple/list treer$)r)r]r�r�rr�r4�sum)rbrZr�r�rOrP�countsrLrrrr4�s
r4�)ReportLab PDF Library - www.reportlab.comc@sLeZdZdZeZdZdZdZdZ	dZ
dZdd	�Zd
d�Z
dd
�Zdd�ZdS)riz�PDF documents can have basic information embedded, viewable from
    File | Document Info in Acrobat Reader.  If this is wrong, you get
    Postscript errors while printing, even though it does not print.r��untitled�	anonymous�unspecifiedr�NcCs
d|_dS)N�False)�trappedrIrrrrv�ruzPDFInfo.__init__cCs,|j|j|j|jfD]	}|�t|��q
dSrC)r�r�r�r�rWr)r?�	md5objectr,rrrr�s�zPDFInfo.digestcCs�i}t|j�|d<t|j�|d<t|j|jd�|d<|d<t|j�|d<t|j�|d<t|j�|d<t|j	�|d	<t
|j�|d
<t|�}|�
|�S)NrO�Author)�tsr��ModDate�CreationDate�Producer�Creator�Subject�Keywords�Trapped)rcr�r��PDFDaterXr�r�r�r�r�r�r�rkr1rmrrrr1s
zPDFInfo.formatcCs,|��}|j��D]
\}}t|||�q	|S)z'shallow copy - useful in pagecatchering)�	__klass__�__dict__r�r
)r?r�r~r�rrrrnszPDFInfo.copy)rrrrLr�r�r�r�r�r�r�r�rvr�r1rnrrrrri�sric@sLeZdZdZded�fgZdZedZddd�Zd	d
�Z	dd�Z
d
d�ZdS)�
Annotationzsuperclass for all annotations.r��Annot)r��Rectr�Subtype)�Border�C�T�M�F�H�BS�AA�AS�Popupr@�APr$cCs2|d}t|�st|�|d<t|d|�|d<|S)�@transform dict args from python form to pdf string rep as neededr�r)rr�rc)r?�drOr�rrr�cvtdict#s
zAnnotation.cvtdictcKs�d|vr|d}|d=nd}i}|jD]\}}|||<q|�|�|jD]}||vr0td|��q$|j||d�}|j}|��D]}||vrOtd|jj|f��q?t	|�S)NrOr$�keyword argument %s missing)rOz$%s bad annotation dictionary name %s)
r�rW�requiredr�r��	permittedr}r�rrk)r?�kwrOr�r��valr�rrr�AnnotationDict*s&


��zAnnotation.AnnotationDictcC�td��)NzEDictString undefined for virtual superclass Annotation, must overload�r�rIrrr�Dict=r=zAnnotation.DictcCs|��}|�|�SrC�r�r1�r?r8r)rrrr1As
zAnnotation.formatNr3)rrrrLr�r�r�r�r�r�r�r1rrrrr�s
r�c@�&eZdZejdZdd�Zdd�ZdS)�FreeTextAnnotation)�DAcK�||_||_||_||_dSrC)r�rr��otherkw)r?r�rr�r�rrrrvG�
zFreeTextAnnotation.__init__cCsFi}|�|j�|j|d<|j|d<|j|d<d|d<|jdi|��S)Nr�rr�z	/FreeTextr�r)rWr�r�rr�r��r?r�rrrr�Ls


zFreeTextAnnotation.DictN)rrrr�r�rvr�rrrrr�Es
r�c@s0eZdZejdZd
dd�Zdd�Zdd�Zd	S)�LinkAnnotation)rPr<�PA�[0 0 1]cKs"||_||_||_||_||_dSrC)r�r�r�Destinationr�)r?r�rr�r�r�rrrrvYr[zLinkAnnotation.__init__cCr)Nz�
          << /Type /Annot /Subtype /Link /Rect [71 717 190 734] /Border [16 16 1]
             /Dest [23 0 R /Fit] >>
             rrIrrr�dummyDictString`rBzLinkAnnotation.dummyDictStringcCsPi}|�|j�|j|d<|j|d<|j|d<d|d<|j|d<|jdi|��S)Nr�r�rz/Linkr�rPr)rWr�r�r�rr�r�r�rrrr�fs



zLinkAnnotation.DictN)r�)rrrr�r�rvr�r�rrrrr�Us


r�c@s<eZdZdZejdZgd�fdd�Zddd�Zd	d
�ZdS)
�HighlightAnnotationa
    HighlightAnnotation is an annotation that highlights the selected area.

    Rect is the mouseover area that will show the contents.

    QuadPoints is a list of points to highlight, you can have many groups of
    four QuadPoints to allow highlighting many lines.
    )�
QuadPoints)g��(\��?g{�G�z�?gffffff�?cKs"||_||_||_||_||_dSrC)r�rr�r��Color)r?r�rr�r�r�rrrrv{r[zHighlightAnnotation.__init__r$cCs�|d}|d}|d}t|t�st|�j|dd�|d<t|t�s,t|�j|dd�|d<t|t�s<t|�j|dd�|d<t|d|�|d<|S)r�r�r�r�rxr�r)r)r*r�r1rc)r?r�rOr��Quadr�rrrr��s


zHighlightAnnotation.cvtdictcCsPi}|�|j�|j|d<|j|d<d|d<|j|d<|j|d<|jdi|��S)Nr�rz
/Highlightr�r�r�r)rWr�r�rr�r�r�r�rrrr��s



zHighlightAnnotation.DictNr3)	rrrrLr�r�rvr�r�rrrrr�ps

r�c@r�)�TextAnnotation)�Open�NamecKs8tj|||f|�dd�pt|�|�dd�d�|��dS)Nr�r�)rrr)r�r�)r�rvr��rect_to_quad)r?r�rr�rrrrv�s�
�
�zTextAnnotation.__init__cCst�|�}d|d<|S)Nz/Textr�)r�r�r�rrrr��s
zTextAnnotation.DictN)rrrr�r�rvr�rrrrr��s
r�c	Cs4|d|d|d|d|d|d|d|dgS)z9
    Utility method to convert a Rect to a QuadPoint
    rr$rTr%r)r�rrrr��s�r�c@r�)�PDFRectanglecCs ||||f\|_|_|_|_dSrC)�llx�lly�ulx�ury)r?r�r��urxr�rrrrv�s zPDFRectangle.__init__cCs"t|j|j|j|jg�}t||�SrC)r�r�r�r�r�r1)r?r8r<rrrr1�s
zPDFRectangle.formatNr�rrrrr��r�r�c@s&eZdZddd�Zdd�Zdd�ZdS)	r�NcCs"|durt�}|�|�||_dSrC)r�_initr�)r?r�r�rrrrv�s

zPDFDate.__init__cCs|j|_|j|_|j|_dSrC)�YMDhms�date�dhh�dmm)r?r�rrrr��sz
PDFDate._initcCs"|jpdd�}tt||j��|�S)NcSsd||||||fS)Nz!D:%04d%02d%02d%02d%02d%02d+00'00'r)�yyyy�mm�dd�hh�mrFrrr�<lambda>�s�z PDFDate.format.<locals>.<lambda>)r�r1rcr�)r?r��dfmtrrrr1�s�zPDFDate.formatr�)rrrrvr�r1rrrrr��s
r�c@steZdZdZdZZZdd�Zdd�Zdd�Zd	d
�Z	dd�Z
d
d�Zdd�Zdd�Z
dd�Zdd�Zdd�ZdS)r�aM

    not a PDFObject!  This is a placeholder that can delegates
    to a pdf object only after it has been defined by the methods
    below.

    EG a Destination can refer to Appendix A before it has been
    defined, but only if Appendix A is explicitly noted as a destination
    and resolved before the document is generated...

    For example the following sequence causes resolution before doc generation.
        d = Destination()
        d.fit() # or other format defining method call
        d.setPage(p)
        (at present setPageRef is called on generation of the page).
    NcCs||_d|_|_dSrC)r��fmtr�r&rrrrv�szDestination.__init__cCsH|j}|durtd|j��|j}|durtd|j��||_|�|�S)NzYformat not resolved, probably missing URL scheme or undefined destination target for '%s'zTPage not bound, probably missing URL scheme or undefined destination target for '%s')r�r�r�r�r1)r?r8r:�prrrr1�s
zDestination.formatcCstd|||�|_dSrC)�PDFDestinationXYZr�)r?�left�top�zoomrrr�xyz�r�zDestination.xyzcC�td�|_dSrC)�PDFDestinationFitr�rIrrr�fit�r�zDestination.fitcCr�rC)�PDFDestinationFitBr�rIrrr�fitb�r�zDestination.fitbcC�td|�|_dSrC)�PDFDestinationFitHr��r?r�rrr�fith�r�zDestination.fithcCr�rC)�PDFDestinationFitVr��r?r�rrr�fitv�r�zDestination.fitvcCr�rC)�PDFDestinationFitBHr�r�rrr�fitbh�r�zDestination.fitbhcCr�rC)�PDFDestinationFitBVr�r�rrr�fitbv�r�zDestination.fitbvcCstd||||�|_dSrC)�PDFDestinationFitRr�)r?r��bottom�rightr�rrr�fitr�r�zDestination.fitrcCrwrC�r�rrrr�setPage�ruzDestination.setPage)rrrrL�representationr1r�rvr�r�r�r�r�r�r�r�r�rrrrr��sr�c@r�)r��XYZcCs||_||_||_||_dSrC)r�r�r�r�)r?r�r�r�r�rrrrvr�zPDFDestinationXYZ.__init__cCs4|�|j�}t|t|j�|j|j|jg�}t||�SrC)	r0r�r�r��typenamer�r�r�r1�r?r8�pagerefr<rrrr1s
zPDFDestinationXYZ.formatN�rrrrrvr1rrrrr�sr�c@r�)r��FitcCrwrCr�rrrrrvruzPDFDestinationFit.__init__cCs(|�|j�}t|t|j�g�}t||�SrC)r0r�r�r�rr1rrrrr1s
zPDFDestinationFit.formatNrrrrrr��r�c@r�)r��FitBN�rrrrrrrrr�r�r�c@r�)r��FitHcCr7rC)r�r�)r?r�r�rrrrvr�zPDFDestinationFitH.__init__cC�,|�|j�}t|t|j�|jg�}t||�SrC)r0r�r�r�rr�r1rrrrr1�
zPDFDestinationFitH.formatNrrrrrr�rr�c@r�)r��FitBHNrrrrrr�!r�r�c@r�)r��FitVcCr7rC)r�r�)r?r�r�rrrrv&r�zPDFDestinationFitV.__init__cCr	rC)r0r�r�r�rr�r1rrrrr1(r
zPDFDestinationFitV.formatNrrrrrr�$rr�c@r�)r��FitBVNrrrrrr�-r�r�c@r�)r��FitRcCs"||_||_||_||_||_dSrC)r�r�r�r�r�)r?r�r�r�r�r�rrrrv2s"zPDFDestinationFitR.__init__cCs8|�|j�}t|t|j�|j|j|j|jg�}t	||�SrC)
r0r�r�r�rr�r�r�r�r1rrrrr14s"
zPDFDestinationFitR.formatNrrrrrr�0rr�c@s^eZdZdZdd�Zdd�d��D�ZdZdd	�Zd
d�Z	dd
�Z
dd�Zdd�Zdd�Z
dS)rz7each element *could* be reset to a reference if desiredcKsD|jD]}t|||�|i��q|��d|vr |�d�|_dSdS�N�ProcSet)�dict_attributesr
r�r r)r?�kwds�_rrrrv?s
�zPDFResourceDictionary.__init__cCsg|]}t|��qSr)r��rzrFrrrr|Fr2z PDFResourceDictionary.<listcomp>zPDF Text ImageB ImageC ImageI)�
ColorSpacer"r#�Font�Pattern�
Properties�ShadingcCs|j|_dSrC��stdprocsrrIrrrrIszPDFResourceDictionary.allProcscCs|jdd�|_dS)NrTrrIrrrr Mr�z PDFResourceDictionary.basicProcscCstt�|_dSrC)r�r"rrIrrrrPr�z PDFResourceDictionary.basicFontscC�$|��D]\}}t|�|j|<qdSrC)r�r�r)r?�
colorsUsedrGrFrrrr&S��z#PDFResourceDictionary.setColorSpacecCrrC)r�r�r)r?�shadingUsedrGrFrrrr$Wrz PDFResourceDictionary.setShadingcCs�i}|jD]}t||�}t|t�r|rt|�}|||<q|||<q|j}d}t|�r5|r4t|�}|||<n|||<t|�}t||�Sr)	rr�r)r rkrrr�r1)r?r8r)�dnamer��dvrurrrr1[s&


�
�
zPDFResourceDictionary.formatN)rrrrLrvr�rrrr rr&r$r1rrrrr=src@s4eZdZdZdZd��ZdZdZd��Z	dd�Z
d	S)
�PDFType1Fontz"no init: set attributes explicitlyr$zType Subtype BaseFont Namer�Type1z;FirstChar LastChar Widths Encoding ToUnicode FontDescriptorcCsji}|jD]}t||�rt||�}t|�||<q|jD]}t||�r+t||�}|||<qt|�}|�|�SrC)�name_attributesr/r�r��local_attributesrkr1)r?r8r)r�r�rTrrrr1s


�


�
zPDFType1Font.formatN)rrrrLr r�r$r�r�r%r1rrrrr"vsr"c@r�)�PDFTrueTypeFont�TrueTypeN)rrrr�rrrrr&�r�r&c@sPeZdZdZZZZZZZ	dZ
dZdd�Zdd�Z
dd	�Zd
d�ZdS)rNr$rcCr�rC)�lowerx�lowery�upperx�uppery)r?r(r)r*r+rrrrv�szPDFFormXObject.__init__cCs t|�r	d�|�}t|�|_dS)NrU)rrir-r)r?r�rrr�
setStreamList�s
zPDFFormXObject.setStreamListcCs&|jr	t|jj�S|j|j|j|jgS)z4get the declared bounding box for the form as a list)�BBoxr�r!r(r)r*r+rIrrrr�szPDFFormXObject.BBoxListcCs,|jpt|j|j|j|jg�|_|jptgd��|_|js!d|_ntd��|j	s>|j
}|s2t�|_	nt�}||_
d|_||_	|js^t�}|��|jrP|��n|��|jr[|j|_||_|jrmtjrhttgpjtg|j	_|j	j}td�|d<td�|d<d|d	<|j|d
<|j|d<|j|d<|j	�|�S)
N)r$rrr$rrz-annotations don't work in PDFFormXObjects yetzxobject form streamr"r��Formr�r$�FormTyper-�Matrixr) r-r�r(r)r*r+r0rr�rrr�rr�r!rrrrrr r!r"rnrr�r�r�r�rr�r1)r?r8rr�r(�sdictrrrr1�s@ 




zPDFFormXObject.format)rrrr!rr-r0rrrrrnrvr,rr1rrrrr�src@s"eZdZdZddd�Zdd�ZdS)�PDFPostScriptXObjectz,For embedding PD (e.g. tray commands) in PDFNcCrwrC�r�)r?r�rrrrv�ruzPDFPostScriptXObject.__init__cCs<t�}|j|_d|_|j}td�|d<td�|d<|�|�S)Nzxobject postscript streamr"r��PSr�)rr�r!rr�r1)r?r8r�r1rrrr1�s
zPDFPostScriptXObject.formatrC)rrrrLrvr1rrrrr2�s
r2�	DeviceRGB�
DeviceGray�
DeviceCMYK)�RGBrl�CMYKc@sFeZdZddd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dS)�PDFImageXObjectNcCs�||_d|_d|_d|_d|_tjrdpd|_d|_||_	|dur#dSt
|d�r/|�|�dSd	dl}|j
�|�d��}t|�}z,|d
vrK|�|�s`tjrT|�|�n|�|�W|��dSW|��dSW|��dS|��w)N��r$r6)r�rz�
            003B00 002700 002480 0E4940 114920 14B220 3CB650
            75FE88 17FF8C 175F14 1C07E2 3803C4 703182 F8EDFC
            B2BBC2 BB6F84 31BFC2 18EA3C 0E3E00 07FC00 03F800
            1E1800 1FF800>
            �jpeg_fhr)z.jpgz.jpeg)r��width�height�bitsPerComponent�
colorSpacerr��_filters�
streamContent�maskr/�loadImageFromSRCr��path�splitext�lowerr�loadImageFromJPEG�loadImageFromA85�loadImageFromRawr�)r?r��sourcerDr��ext�srcrrrrvs2
��zPDFImageXObject.__init__cCs�g}tj||dd�}|s|�|d�Sdd�|D�}|d��}t|d�t|d�|_|_dd	d
d�|d|_d
|_d|_	|rJ|�
|d�n|jdkrRd|_d�|dd��|_
dS)NT��IMG�
detectJpegrcSsg|]}|���qSr)r�rrrrr|.r2z4PDFImageXObject.loadImageFromA85.<locals>.<listcomp>r$r%r5r6r7�z/RGBz/Gz/CMYK���r�r�rNr�rU)r�makeA85ImagerEr�r6r>r?rAr@rB�_checkTransparencyrDrirC�r?rLrP�	imagedata�wordsrrrrJ)sz PDFImageXObject.loadImageFromA85c	Cs�zzt�|�}W|�d�n|�d�wWnYdS|d|d|_|_d|_|ddkr4d|_n|ddkr>d|_nd	|_d|_|��|_	t
jrVt|j	�|_	d
|_
nd|_
d|_dS)
NrFr$rTrTr6r%r5r7)r��	DCTDecode)r[T)r�readJPEGInfo�seekr>r?r@rA�_dotrans�readrCrr�rrBrD)r?�	imageFilerJrrrrI8s*
z!PDFImageXObject.loadImageFromJPEGcCs�g}tj||dd�}|s|�|d�S|d��}t|d�|_t|d�|_dddd	�|d
|_d|_d|_	|rB|�
|d�n|jd
krJd|_d�|dd��|_
dS)NTrOrr$r%r5r6r7rRrSrT�r�rNr�rU)r�makeRawImagerEr�r6r>r?rAr@rBrWrDrirCrXrrrrKRsz PDFImageXObject.loadImageFromRawcCs�|jdkrC|jr!d|_tt|j���|jdd�|_ddg|j_dS|��}|r>|d|d|d|d|d|df|_dSd|_dSt|jd�re|j�	�}|d|d|d|d|d|df|_dSdS)NrN)rDrr$rT�rgb)
rD�_dataAr:r
�
getRGBData�_smask�_decode�getTransparentr/rc)r?�im�tcrrrrrWas
.

.�z"PDFImageXObject._checkTransparencycCs~|��}|r
|�|�dS|��\|_|_|��}t�|�|_t	j
r,t|j�|_d|_nd|_t
|j|_d|_|�|�dS)z%Extracts the stream, width and heightrUrarTN)r=rI�getSizer>r?rer�r�rCrr�rrB�_mode2CSrrAr@rW)r?ri�fpr�rrrrEqsz PDFImageXObject.loadImageFromSRCcCs�t|jd�}|j}td�|d<td�|d<|j|d<|j|d<|j|d<t|j�|d	<|jd
kr?t|dd�r?t	gd
��|d<n
t|dd�rLt	|j
�|d<t	tt|j��|d<t
|j�|d<|jrgt	|j�|d<t|dd�rr|j|d<|�|�S)Nr3r"r��Imager��Width�Height�BitsPerComponentrr7r^r)r$rr$rr$rr$r�Decodergr�r��Mask�smask�SMask)rrCrr�r>r?r@rAr�r�rgr�rBr�rDrtr1)r?r8r�r rrrr1�s"



zPDFImageXObject.formatr�)
rrrrvrJrIrKrWrEr1rrrrr:s
!r:c@r�)r�cCsFddlm}t||�std|jj��|jstd|jj��||_dS)Nr)�	CMYKColorz%s needs a CMYKColor argumentz-%s needs a CMYKColor argument with a spotName)�reportlab.lib.colorsrvr)r�r�rr�r�)r?r�rvrrrrv�s

zPDFSeparationCMYKColor.__init__cCs�gj}t|j���D]?\}}t|�}|dkr.|dkr#|d�|d�q
|t|��|d�q
|dkr7|d�n|d�|t|��|d�|d�q
d	d
�|j�S)zpcreate the postscript code for the tint transfer function
        effectively this is tint*c, tint*y, ... tint*kr%�r�z0.0�mulr�dup�exchz{%s}� )r�rfr�r5r*ri�__self__)r?r,rmr�rrr�_makeFuncPS�s 



z"PDFSeparationCMYKColor._makeFuncPScCsDttd�t|jj�td�tttdtd�td�d��|��dd�f�S)N�
Separationr7r&)rr$)rr$rr$rr$rr$)�FunctionType�Domain�Range)rr�r�)r�r�r�r�rrkr r~rIrrrr��s
���zPDFSeparationCMYKColor.valueN)rrrrvr~r�rrrrr��sr�c@s8eZdZdZgZdZedZdd�Zdd�Zdd	�Z	d
S)�PDFFunctionz"superclass for all function types.)r�r�)r�cKsvi}|jD]\}}|||<q|�|�|jD]}||vr"td|��q|j}|��D]}||vr6td|��q*t|�S�Nr�z!bad annotation dictionary name %s)r�rWr�r�r�r}rk)r?r�r�r�r�r�rrr�FunctionDict�s


��zPDFFunction.FunctionDictcCr��Nz?Dict undefined for virtual superclass PDFShading, must overloadr�rDrrrr��r=zPDFFunction.DictcC�|�|�}|�|�SrCr�r�rrrr1��

zPDFFunction.formatN)
rrrrLr�r�r�r�r�r1rrrrr��sr�c@sDeZdZejded�fgZejdZejdZdd�Zdd�Z	d	S)
�PDFExponentialFunctionr�)rxg�?)�N)�C0�C1r�cKr�rC)r�r�r�r�)r?r�r�r�r�rrrrv�r�zPDFExponentialFunction.__init__cCsNi}|�|j�d|d<t|j�|d<t|j�|d<|j|d<|jdi|��S)NrTr�r�r�r�r)rWr�r�r�r�r�r��r?r8r�rrrr��s
zPDFExponentialFunction.DictN)
rrrr�r�r�r�r�rvr�rrrrr��s

r�c@s0eZdZejdZejdZdd�Zdd�ZdS)�PDFStitchingFunction)�	Functions�Bounds�EncodecKr�rC)r�r�r�r�)r?r�r�r�r�rrrrv�r�zPDFStitchingFunction.__init__cs`i}|�|j�d|d<t�fdd�|jD��|d<t|j�|d<t|j�|d<|jdi|��S)	Nr%r�csg|]}��|��qSr)r0r1r�rrr|	r�z-PDFStitchingFunction.Dict.<locals>.<listcomp>r�r�r�r)rWr�r�r�r�r�r�r�rr�rr��szPDFStitchingFunction.DictN)rrrr�r�r�rvr�rrrrr��s


r�c@s4eZdZdZdZedZdd�Zdd�Zdd	�Zd
S)�
PDFShadingz!superclass for all shading types.)�ShadingTyper)�
Backgroundr-�	AntiAliascKs^i}|�|�|jD]}||vrtd|��q
|j}|��D]}||vr*td|��qt|�Sr�)rWr�r�r�r}rk)r?r�r�r�r�rrr�ShadingDict
	s

��zPDFShading.ShadingDictcCr�r�r�rDrrrr�	r=zPDFShading.DictcCr�rCr�r�rrrr1	r�zPDFShading.formatN)	rrrrLr�r�r�r�r1rrrrr�	sr�c@�0eZdZejdZejdZdd�Zdd�ZdS)�PDFFunctionShading)�Function)r�r0r�cKs||_||_||_dSrC)r�rr�)r?r�rr�rrrrv"	s
zPDFFunctionShading.__init__cCsFi}|�|j�d|d<t|j�|d<|�|j�|d<|jdi|��S)Nr$r�rr�r)rWr�r�rr0r�r�r�rrrr�&	szPDFFunctionShading.DictN�rrrr�r�r�rvr�rrrrr�	s


r�c@r�)�PDFAxialShading��Coordsr��r�r�r��ExtendcKs$||||f|_||_||_||_dSrC�r�r�rr�)r?�x0�y0�x1�y1r�rr�rrrrv2	s
zPDFAxialShading.__init__cC�Ti}|�|j�d|d<t|j�|d<t|j�|d<|�|j�|d<|jdi|��S)NrTr�rr�r�r�	rWr�r�rr�r�r0r�r�r�rrrr�7	�zPDFAxialShading.DictNr�rrrrr�.	�


r�c@r�)�PDFRadialShadingr�r�c	
Ks(||||||f|_||_||_|	|_dSrCr�)
r?r�r��r0r�r��r1r�rr�rrrrvD	s
zPDFRadialShading.__init__cCr�)Nr%r�rr�r�rr�r�rrrr�I	r�zPDFRadialShading.DictNr�rrrrr�@	r�r��__main__z-There is no script interpretation for pdfdoc.r0rC)��__version__rLr;rZr��collectionsrr�r�	reportlabrr�rrrrr	r
rrr
r�reportlab.lib.rl_accelrrrrr�hashlibr�sysr�	Exceptionrrr r!r"r#r2r r|r-r1r<�formNamer>r.rKrN�PDFtrue�PDFfalse�PDFnullr�rA�re�compilerDrHrMrc�chrr�rkr�r�r�r�r�r�r�r�rr�r�r�r�r�r�r�r�r�rr^rarr*r+r:rLrMrerNrfr4r�rir�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rr"r&rr2rlr:r�r�r�r�r�r�r�r�rr�rrrr�<module>s�0�
&
I
-	

*	%4W(K

A*(*0			
9#@0
�

Youez - 2016 - github.com/yon3zu
LinuXploit