+
    ˧6j                         ^ RI t ^ RIt^ RIt^ RIt^ RIt^ RIHtHtHt ^RI	H
t
 R tR tRR ltR tR tRR	 ltR
 tR tR tR tR tR tR tR tR tR tR tR tR tR tR tR t ]!R8X  d
   ] ! 4        R# R# )    N)DictListSet)pymupdfc                 .    R V  R 2P                  ^KR4      # ) -)center)xs   &H/opt/hart-platform/venv/lib/python3.14/site-packages/pymupdf/__main__.pymycenterr      s    s!HR%%    c                L   V^ ,          pV^,          pV^ 8X  d   V P                  V4      # R p\        P                  ! W4      p\        P                  ! W4      p VP                  VP                  8X  d8   VP                  VP                  u;8X  d   ^ 8X  d   M MVP
                  ^8X  g>   \        P                  ! RV RV R24       \        P                  ! V4       RpV! V4      # \        P                  ! V4      pVP                  VP                  4       R;rVV! V4      # )zReturn image for a given XREF.c                     V P                   P                  ^8w  d   V # \        P                  ! \        P                  V 4      pV# )   )
colorspacenr   PixmapcsRGB)pixtpixs   & r   getimagerecoverpix.<locals>.getimage   s2    >>q J~~gmmS1r   zWarning: unsupported /SMask z for :N)	extract_imager   r   irectalphar   message	set_alphasamples)docitemr   sr   pix1pix2r   s   &&      r   
recoverpixr&      s    QAQAAv  ## >>#!D>>#!D
 JJ$**$tzz)FQ)F466UV;6qcqcCD~
..
CMM$,,D C=r   c                   \         P                  ! V 4      pVP                  '       g   VRJ d   \        P                  ! R4       R	pVP
                  '       g   V# V'       d\   VP                  V4      pV'       g   \        P                  ! R4       VRJ d%   RpV^8  d   Rp\         P                  ! RV 24       V# \        P                  ! RVP                   R24       V# )
z!Open and authenticate a document.Tz$this command supports PDF files onlyzauthentication unsuccessfuluserownerzauthenticated as 'z' requires a password)	r   openis_pdfsysexit
needs_passauthenticater   name)filenamepasswordshowpdfr!   rc
auth_levels   &&&&   r   	open_filer9   9   s    
,,x
 C:::#+78	B>>>
h'HH234<JAv$
OO/
|<= J 	1SXXJ345Jr   c                   \        V P                  4        Uu. uF  p\        V4      NK  	  up4      ^,           pV P                  4        F1  w  rVP	                  V4       RV 2p\
        P                  ! V4       K3  	  R# u upi )zPrint a Python dictionary.: N)maxkeyslenitemsrjustr   r   )r"   klvmsgs   &    r   
print_dictrE   O   se    TYY[)[SV[)*Q.A

Bqc"  *s   Bc                   \         P                  ! VR R24       V P                  V4      p\         P                  ! V4       V P                  V4      '       d{   VP	                  4       p VP                  R4      ^,           pW4,          pVP                  R4      '       d   Rp\         P                  ! RT R24       \         P                  ! R4       \         P                  ! R	4       R
#   \         d    Rp LWi ; i)zuPrint an object given by XREF number.

Simulate the PDF source in "pretty" format.
For a stream also print its size.
dz 0 objz/Lengthz0 Runknownz
stream
...z bytes	endstreamendobjN)r   r   xref_objectxref_is_streamsplitindexendswith	Exception)r!   xrefxref_strtempidxsizes   &&    r   
print_xrefrV   W   s     OOtAhf%&t$HOOH
$~~	**Y'!+C9D}}U##  	+dV623$OOH	  	D	s   *9C+ +C;:C;c           	        \        V^,
          4      pV P                  RV4      P                  RR4      p V P                  R4      p. p\        V4       EFO  w  rgV^,           pVP	                  4       '       dX   \        V4      p	^T	u;8:  d   V8  d   M MVP                  \        V4      4       M\        P                  ! RV RVR 24       K|   VP                  R4      w  r\        V
4      p
\        V4      p^X
u;8:  d   V8  d   M M^Xu;8:  d   V8  g    M \        P                  ! RV R	VR 24       V
X8X  d   VP                  V
4       EK  W8  d&   V\        \        W^,           4      4      ,          pEK,  V\        \        W^,
          R
4      4      ,          pEKR  	  V#   \         d!    \        P                  ! RT R	TR 24        Li ; i)a'  Transform a page / xref specification into a list of integers.

Args
----
    rlist: (str) the specification
    limit: maximum number, i.e. number of pages, number of objects
    what: a string to be used in error messages
Returns
-------
    A list of integers representing the specification.
Nr    ,zbad z specification at item rG   r	   z range specification at item r+   )strreplacerM   	enumerate	isdecimalintappendr.   r/   rP   listrange)rlistlimitwhatrX   	rlist_arrout_listseqr"   r   ii1i2s   &&&         r   get_listrl   n   s    	EAIAMM#q!))#r2EC IHy)	!G>>D	AA~~D	*4v%<QqEBC	FZZ_FBRBRB R%AOeOHHtD6!>qeDE8OOB7U2Av.//HU2Avr233H5 *8 O  	FHHtD6!>qeDE	Fs   )F))(GGc                    \        V P                  V P                  R 4      p\        P                  P                  V P                  4      R,          pRpVR8  d   VR,          pRp\        V^4      pVP                  p\        P                  ! RV P                  VP                  VP                  4       ^,
          VVVR,          VR,          3,          4       VP                  pV^ 8  d9   VP                  4       pRpV^8w  d   R	p\        P                  ! R
V RV R24       VP                  4       pV^ 8  d   \        P                  ! R
VR R24       \        P                  ! 4        V P                  '       dP   \        P                  ! \!        R4      4       VP#                  4       p\%        W4       \        P                  ! 4        V P                  '       dJ   \        P                  ! \!        R4      4       \'        VP                  4       \        P                  ! 4        V P(                  '       do   \        P                  ! \!        R4      4       \+        V P(                  VP                  4       RR7      p	V	 F#  p\%        W4       \        P                  ! 4        K%  	  V P,                  '       d   \        P                  ! \!        R4      4       \+        V P,                  VP                  ^,           4      p
V
 FX  pV^,
          pVP/                  V4      p\        P                  ! RVR R24       \%        W4       \        P                  ! 4        KZ  	  V P0                  '       dY   \        P                  ! \!        R4      4       \        P                  ! VP3                  4       4       \        P                  ! 4        VP5                  4        R# )Ti   KBi  MBz7'%s', pages: %i, objects: %i, %g %s, %s, encryption: %sformat
encryptionrY   znot zdocument contains z root form fields and is signedrG    embedded fileszPDF catalogzPDF metadatazobject informationrQ   )re   zpage informationzPage r   zPDF trailerN)r9   inputr4   ospathgetsizeroundmetadatar   r   
page_countxref_lengthis_form_pdfget_sigflagsembfile_countcatalogr   pdf_catalogrV   rE   xrefsrl   pages	page_xreftrailerpdf_trailerclose)argsr!   rU   flagmetar   r#   sign_strrQ   xreflpagelpnos   &           r   r5   r5      s   
DJJt
4C77??4::&-DDd{q>D<<DOOAJJNNOO!N
		
 	A1u6H,QC/H
RXYZA1u,QqEABOO|||/0 3}}}013<< zzz!567S__%6VDDs!OO  zzz!345S^^a%78CaA==#DOOeC7!,-s!OO  |||/0)*IIKr   c                    \        V P                  V P                  R R7      pV P                  pRP	                  V4      pV P
                  '       g   VP                  V P                  V P                  V P                  V P                  V P                  V P                  V P                  VV P                  V P                  V P                   R7       R# \#        V P
                  VP$                  ^,           4      p\&        P(                  ! 4       pV F  pV^,
          pVP+                  WVR7       K!  	  VP                  V P                  V P                  V P                  V P                  V P                  V P                  V P                  VV P                  V P                  V P                   R7       VP-                  4        VP-                  4        R# )Tr6   )
garbagedeflateprettycleanasciilinearrq   owner_pwuser_pwpermissionsN	from_pageto_pagekeepnonezrc4-40zrc4-128zaes-128zaes-256)r9   rt   r4   rq   rN   r   saveoutputr   compressr   sanitizer   r   r)   r(   
permissionrl   rz   r   r,   
insert_pdfr   )r   r!   rq   encryptr   outdocr   r   s   &       r   r   r      s]   
DJJ4
8CJIOOG :::KKLLMM;;--**;;ZZII 	 	
 	 TZZ!!34E\\^F!G#A6  KK{{mmjj{{		OO   IIK
LLN
r   c                   V P                   p\        P                  ! 4       pV F  pVP                  R4      p\	        V4      ^8  d
   V^,          MRp\        V^ ,          VRR7      pRP                  VR,          4      pV'       d5   \        RP                  VR,          4      VP                  ^,           4      pM\        ^VP                  ^,           4      pV F$  p	VP                  Wi^,
          V	^,
          R7       K&  	  VP                  4        K  	  VP                  V P                  ^RR7       VP                  4        R# )z&Join pages from several PDF documents.rZ   NTr   :   NNr   )r   r   )rt   r   r,   rM   r>   r9   joinrl   rz   rb   r   r   r   r   )
r   doc_listr!   src_itemsrc_listr4   srcr   	page_listri   s
   &         r   doc_joinr     s    zzH
,,.C>>#&"%h-!"38A;X48"& (2,!7!9KLIa!!34IANN3a%QN? 		  HHT[[!TH2IIKr   c           	        \        V P                  V P                  RR7      pVP                  4       '       gD   V P                  '       d   V P                  V P                  8X  d   \
        P                  ! R4       \        V P                  V P                  4      pV P                  '       d   \        V P                  4      M	\        4       p\        VP                  4       4      pV'       d   W48:  g   \
        P                  ! R4       MTpV'       g   \
        P                  ! R4       V\        VP                  4       4      ,          pV'       d#   \
        P                  ! R\        V4       24       V Fw  pVP                  V4      pVP                  V4      pVP                  VVVR,          VR,          VR	,          R
7       \         P"                  ! RV RVP                   R24       Ky  	  VP%                  4        V P                  '       d:   V P                  V P                  8w  d   VP'                  V P                  ^R7       MVP)                  4        VP%                  4        R# )z!Copy embedded files between PDFs.Tr   cannot save PDF incrementallyz%not all names are contained in sourceznothing to copyz0following names already exist in receiving PDF: r3   	ufilenamedescr3   r   r   zcopied entry 'z' from 'r*   r   N)r9   rt   r4   can_save_incrementallyr   r.   r/   source	pwdsourcer2   setembfile_namesr[   embfile_infoembfile_getembfile_addr   r   r   r   saveIncr)	r   r!   r   names	src_names	intersectr"   infobuffs	   &        r   embedded_copyr      s   
DJJ4
8C%%''KKK4;;$**401
DKK
0C"iiiC		NSUEC%%'(I!HH<="#C--/00ICC	NCSTU%t$*%;'f 	 	
 	.hsxxjBC  IIK{{{t{{djj0a(IIKr   c                   \        V P                  V P                  RR7      pVP                  4       '       gD   V P                  '       d   V P                  V P                  8X  d   \
        P                  ! R4        VP                  V P                  4       V P                  '       d   V P                  V P                  8X  d   VP                  4        MVP                  V P                  ^R7       VP                  4        R#   \        \        P                  P                  3 d2   p\
        P                  ! RT P                  : RT 24        Rp?LRp?ii ; i)zDelete an embedded file entry.Tr   r   no such embedded file r;   Nr   )r9   rt   r4   r   r   r.   r/   embfile_delr2   
ValueErrorr   mupdfFzErrorBaser   r   r   )r   r!   es   &  r   embedded_delr   H  s    
DJJ4
8C%%''KKK4;;$**401>		" ;;;$++3a(IIK 112 >)$))b<==>s   =D %E*'EEc                \   \        V P                  V P                  RR7      p VP                  V P                  4      pVP                  V P                  4      pV P                  '       d   V P                  MXR,          pV P                  '       g   V P                  '       g   \        P                  P!                  V4      '       d   \        P                  ! RV 24       \        P                  P#                  V4      pVP%                  \        P&                  ! 4       \        P(                  ,           4      '       g   \        P                  ! RV 24       \+        VR	4      ;_uu_ 4       pVP-                  X4       RRR4       \        P.                  ! R
V P                   RV R24       VP1                  4        R#   \        \        P                  P                  3 d3   p\        P                  ! RT P                  : RT 24        Rp?ELRp?ii ; i  + '       g   i     L; i)z&Retrieve contents of an embedded file.Tr   r   r;   Nr3   z6refusing to overwrite existing file with stored name: z9refusing to write stored name outside current directory: wbzsaved entry 'z' as 'r*   )r9   rt   r4   r   r2   r   r   r   r   r   r.   r/   r   unsaferu   rv   existsabspath
startswithgetcwdsepr,   writer   r   )r   r!   streamrG   r   r3   filename_absr   s   &       r   embedded_getr   [  so   
DJJ4
8C>+TYY' #kkkt{{q}H;;;t{{{77>>(##HHMhZXYwwx0&&ryy{RVV';<<HHPQYPZ[\	h		V 
OOmDII;fXJa@AIIK 112 >)$))b<==> 
	s#   6G .H%H&'HHH+	c                   \        V P                  V P                  RR7      pVP                  4       '       g@   V P                  e   V P                  V P                  8X  d   \
        P                  ! R4        VP                  V P                  4       \
        P                  ! RV P                   R24       \        P                  P                  V P                  4      '       d0   \        P                  P                  V P                  4      '       g%   \
        P                  ! RV P                   R24       \        V P                  R	4      ;_uu_ 4       pVP                  4       pRRR4       V P                  pTpV P                   '       g   TpMV P                   pVP#                  V P                  XWEVR
7       V P                  '       d   V P                  V P                  8X  d   VP%                  4        MVP'                  V P                  ^R7       VP)                  4        R#   \         d     ELi ; i  + '       g   i     L; i)zInsert a new embedded file.Tr   Nr   zentry 'z' already existszno such file 'r*   rbr   r   )r9   rt   r4   r   r   r.   r/   r   r2   rP   ru   rv   r   isfiler,   readr   r   r   r   r   r   r!   fr   r3   r   r   s   &      r   embedded_addr   p  s   
DJJ4
8C%%''t{{djj801		"7499+%567 77>>$))$$BGGNN499,E,E>$))A./	dii		! 
yyHI999yyOO		6H   ;;;$++3a(IIK)  
 
	s   9?H, H>,H;:H;>I	c                   \        V P                  V P                  RR7      pVP                  4       '       g@   V P                  e   V P                  V P                  8X  d   \
        P                  ! R4        VP                  V P                  4       V P                  e   \        P                  P                  V P                  4      '       dh   \        P                  P                  V P                  4      '       d9   \        V P                  R4      ;_uu_ 4       pVP                  4       pRRR4       MRpV P                   '       d   V P                   pMRpV P"                  '       d   V P"                  pM!V P                   '       d   V P                   pMRpV P$                  '       d   V P$                  pMRpVP'                  V P                  XWEVR7       V P                  e   V P                  V P                  8X  d   VP)                  4        MVP+                  V P                  ^R	7       VP-                  4        R#   \         d)    \
        P                  ! RT P                   R24        ELi ; i  + '       g   i     ELQ; i)
z0Update contents or metadata of an embedded file.Tr   Nr   no such embedded file 'r*   r   r   r   )r9   rt   r4   r   r   r.   r/   r   r2   rP   rv   ru   r   r   r,   r   r3   r   r   embfile_updr   r   r   r   s   &      r   embedded_updr     s   
DJJ4
8C%%''t{{djj8019#
 			GGNN499%%GGNN499%%$))T""aVVXF #" }}}==~~~NN		MM		yyyyyOO		6H   {{dkkTZZ7a(IIKK  9*499+Q789 #""s   9I I:/I76I7:J	c                f   \        V P                  V P                  RR7      pVP                  4       pV P                  e   V P                  V9  d&   \
        P                  ! RV P                   R24       M\        P                  ! 4        Rp\        V4      ^8  d   Rp\        P                  ! R\        V4      R	 R
V R24       \        P                  ! 4        \        VP                  V P                  4      4       \        P                  ! 4        R# V'       g'   \        P                  ! RVP                   R24       R# \        V4      ^8  d   RVP                   R\        V4      R	 R2pMRVP                   R2p\        P                  ! V4       \        P                  ! 4        V Fm  pV P                  '       g   \        P                  ! V4       K-  VP                  V4      p\        VP                  V4      4       \        P                  ! 4        Ko  	  VP                  4        R# )zList embedded files.Tr   Nr   r*   rY   r#   zprinting 1 of rG   z embedded filer   z' contains no embedded filesz' contains the following rs   z&' contains the following embedded file)r9   rt   r4   r   r2   r.   r/   r   r   r>   rE   r   detailr   )r   r!   r   pluralrD   r2   _s   &      r   embedded_listr     s   
DJJ4
8CEyy99E!HH.tyyk;<OOF5zA~OOnSZN.PQRSOOs''		23OO!CHH:%ABC
5zA~#((4SZN/R#((ABOOCOO{{{OOD!T"3##D)*  IIKr   c           
        V P                   '       g)   V P                  '       g   \        P                  ! R4       \	        V P
                  V P                  RR7      pV P                  '       d)   \        V P                  VP                  ^,           4      pM\        ^VP                  ^,           4      pV P                  '       g/   \        P                  P                  \        P                  4      pMpV P                  p\        P                  P!                  V4      '       d&   \        P                  P#                  V4      '       g   \        P                  ! RV R24       \%        4       p\%        4       pV EF=  pV P                   '       d   VP'                  V^,
          4      pV F  pV^ ,          p	W9  g   K  VP)                  V	4       VP+                  V	4      w  rrVR8X  g	   V'       g   KJ  \        P                  P-                  W:P/                  RR4       RV	 R	V 24      p\1        VR
4      ;_uu_ 4       pVP3                  V4       RRR4       RpK  	  V P                  '       g   K  VP5                  V^,
          4      pV EF%  pV^ ,          p	W9  g   K  VP)                  V	4       \7        W4      p\9        V4      \:        J dj   VR,          pVR,          p\        P                  P-                  VRV	R R	V 24      p\1        VR
4      ;_uu_ 4       pVP3                  V4       RRR4       K  \        P                  P-                  VRV	R R24      pVP<                  P>                  ^8  d   TM$\@        PB                  ! \@        PD                  V4      pVPG                  V4       EK(  	  EK@  	  V P                   '       d(   \@        PH                  ! R\K        V4      R RV R24       V P                  '       d(   \@        PH                  ! R\K        V4      R RV R24       VPM                  4        R#   + '       g   i     EL; i  + '       g   i     EK  ; i)z)Extract images and / or fonts from a PDF.z"neither fonts nor images requestedTr   zoutput directory z does not existzn/ar   r	   .r   Nextimagezimg-rG   z.pngzsaved z fonts to 'r*   z images to ')'fontsimagesr.   r/   r9   rt   r4   r   rl   rz   rb   r   ru   rv   r   curdirr   isdirr   get_page_fontsaddextract_fontr   r\   r,   r   get_page_imagesr&   typedictr   r   r   r   r   r   r   r>   r   )r   r!   r   out_dir
font_xrefsimage_xrefsr   itemlistr"   rQ   fontnamer   r   bufferoutnameoutfiler   imgdatar%   s   &                  r   extract_objectsr     s2   :::dkkk56
DJJ4
8CzzzS^^a%78a!+,;;;''//")),++w''BGGMM',B,BHH(	ABJ%K:::))#'2H Aw)NN4(/2/?/?/E,H1e|6  ggll$4$4S#$>#?qau!MG gt,,f- -!F ! ;;;**373H Aw*OOD)$S/CCyD(!%j"%g,"$'',,w$tAhau8M"N!'400G#MM'2 10 #%'',,w$tAhd8K"L  #~~//!3  !(s!C 
 		'*% !% L zzz&Z 3;wiqIJ{{{&[!1! 4L	KLIIK; -,, 100s   ?Q 	Q	 QQ&c                    V'       d   R M\        ^.4      pV P                  RVR7      pV'       g   V'       g   VP                  V4       R# VP                  VP                  RRR7      4       VP                  V4       R# )   
textflagsNutf8surrogatepasserrors)bytesget_textr   encode)	pagetextoutGRIDfontsize
noformfeed
skip_emptyr  eopr  s	   &&&&&&&  r   page_simpler  +  s`    %5";C==u=-DMM#MM$++f_+=>MM#
r   c                 H   V'       d   R M\        ^.4      pV P                  RVR7      pV. 8X  d   V'       g   VP                  V4       R# VP                  R R7       V F,  p	VP                  V	^,          P	                  RRR7      4       K.  	  VP                  V4       R# )	r  blocksr  Nc                 &    V ^,          V ^ ,          3# )    )bs   &r   <lambda> page_blocksort.<locals>.<lambda>>  s    qtQqTlr   keyr  r  r  )r
  r  r   sortr  )
r  r  r  r  r  r  r  r  r  r  s
   &&&&&&&   r   page_blocksortr   7  s    %5";C]]85]1F|MM#
KK*K+adkk&kAB MM#
r   c                   aa! V'       d   R M\        ^.4      pR R lpR R lp	R VV!3R llp
R R lo!R	 pV P                  R
VR7      R,          pV
! W4      w  rpppV. 8X  d   V'       g   VP                  V4       R# V	! W4      pVP                  R R7       / pV F;  pVw   pppV! VV4      pVP	                  V. 4      pVP                  V4       VVV&   K=  	  \        VP                  4       4      pVP                  4        VV,
          p/ pV Fx  pVV,          p\        V4      pV^8  d   ^VV&   K%  V Uu. uF  pV^,          NK  	  ppVP                  4        \        P                  ! V4      pVV8  d   TpV^ ,          VV&   Kz  	  VVR,          V^ ,          ,
          ,          V\        V4      ,          ,          R,          pV^ ,          pVP                  R 4       V Fq  pVV8  d   VP                  R 4       VV,          pK#  V! VVVV,          VV,          4      p VP                  V R,           P                  RRR7      4       VV,           pKs  	  VP                  V4       R# u upi )r  c                R    V ^8  d   QhR\         \        ,          R\        R\        /# )r   valuesvaluereturn)r   r_   )rp   s   "r   __annotate__!page_layout.<locals>.__annotate__I  s*     H HS	 H# H# Hr   c                    \         P                  ! W4      pV'       d   W^,
          ,          # \        RVR RV  24      h)zFind the right row coordinate.

Args:
    values: (list) y-coordinates of rows.
    value: (int) lookup for this value (y-origin of char).
Returns:
    y-ccordinate of appropriate line for value.
z	Line for gz not found in )bisectbisect_rightRuntimeError)r#  r$  ri   s   && r   find_line_index$page_layout.<locals>.find_line_indexI  s=     .a%= YuQi~fXFGGr   c                F    V ^8  d   QhR\         \        ,          R\        /# )r   rowsr%  )r   r_   r   )rp   s   "r   r&  r'  X  s      #c( T r   c                     \        V 4      p V P                  4        V ^ ,          .pV R,           F*  pW2R,          V,           8  g   K  VP                  V4       K,  	  V# )r   :   NNr+   )ra   r  r`   )r0  r  nrowshs   &&  r   curate_rows page_layout.<locals>.curate_rowsX  sP    Dz		a	bA"I$$Q  r   c                Z    V ^8  d   QhR\         \        ,          R\        P                  /# )r   r  r  )r   r   r   Page)rp   s   "r   r&  r'  a  s"     23 23tDz 23 23r   c           
        < \        4       pVP                  P                  pVP                  P                  pTpTp^ p. pV  EF  p	V	R,           EFx  p
V
R,          R8w  d   K  V
R,          w  rrV^ 8  g   WP                  P                  8  d   KC  W,
          pW_8  d   TpV
R,           EF  pVR,          S8:  d   K  VR,           F  pVR,          w  ppppW,
          pVR,          w  pp\	        \        V4      4      pVP                  V4       VR,          pVV8  d
   VR	8w  d   TpW}8  d   TpV^ 8X  dp   V. 8w  di   VR,          w  ppppVV8X  dT   V\        R
4      8w  d   S! VV,           4      pM(VR8X  d   \        R4      pMVR8X  d   \        R4      pMTpVVVV3VR&   K  VP                  VVVV34       K  	  EK  	  EK{  	  EK  	  WWgV3# )r   linesdirbboxspansrU   charsorigincr      ri     rB     )r2  r   r+   )	r   rectwidthheightr_   rx   r   chrr`   )r  r  r0  
page_widthpage_height	rowheightleftrightr>  blocklinex0y0x1y1rF  spanr@  r   cwidthoxoychold_chold_oxold_oy
old_cwidthligr  joinligatures   &&                          r   process_blocks#page_layout.<locals>.process_blocksa  s   uYY__
ii&&	Eg;&(!%f6R))"2"22% &I MMDF|x/ !']]'(yAr1!#!"8B r^sV"9s#%D :$&E!Q;5B;AFr>FFFJ%|#)S[#8*6v{*CC%'3Y*-f+C%'3Y*-f+C*0C-0&&*,Mb	 (b"b&%9:5 + * ' T D22r   c                0    V ^8  d   QhR\         R\         /# )r   r\  r%  )r[   )rp   s   "r   r&  r'    s      # # r   c                   V R8X  d   \        R4      # V R8X  d   \        R4      # V R8X  d   \        R4      # V R8X  d   \        R4      # V R	8X  d   \        R
4      # V R8X  d   \        R4      # V R8X  d   \        R4      # V # )zReturn ligature character for a given pair / triple of characters.

Args:
    lig: (str) 2/3 characters, e.g. "ff"
Returns:
    Ligature, e.g. "ff" -> chr(0xFB00)
ffrA  fii  fli  ffirB  fflrC  fti  sti  )rG  )r\  s   &r   r]  !page_layout.<locals>.joinligature  s     $;v;D[v;D[v;E\v;E\v;D[v;D[v;
r   c                   RpRp^ p^ pV\         P                  8:  d   \        RVR 24      hV F  pVw  rrW,
          p
W,           pWY8X  d   W,
          VR,          8:  d   K4  V	R8X  d   Wj,
          V,          R8  d   KQ  T	pWV,           8  d   WI,          pTpT
pKn  V	R8X  d   Kw  \        W,          4      \	        V4      ,
          pW8  d   V^8  d   VRV,          ,          pWI,          pTpT
pK  	  VP                  4       # )aF  Produce the text of one output line.

Args:
    left: (float) left most coordinate used on page
    slot: (float) avg width of one character in any font in use.
    minslot: (float) min width for the characters in this line.
    chars: (list[tuple]) characters of this line.
Returns:
    text: (str) text string for this line
rY   z#program error: minslot too small = r)  g?r   g?)r   EPSILONr,  r_   r>   rstrip)rK  slotminslotlcharsr  old_charold_x1rY  r@  charrU  r   rT  rQ  deltas   &&&&           r   make_textline"page_layout.<locals>.make_textline  s    goo%!DWQKPQQA"#DaBB BK6C<$? s{v5;HW$$
 s{	NSY.E{uqye#LDFFA B {{}r   rawdictr  r  Nc                     V ^,          # )r2  r  )r@  s   &r   r  page_layout.<locals>.<lambda>  s    QqTr   r  g333333?
r  r  r  r+   )r
  r  r   r  getr`   ra   r=   r>   
statisticsmedianr  )"r  r  r  r  r  r  r  r  r-  r5  r^  rt  r  r>  r0  rK  rL  rJ  r:  r@  r   rV  yro  r=   rm  minslotsrA   ccountwidths	this_slotrowposr  r]  s"   &&&f&&&                          @r   page_layoutr  E  sD   %5";CH23 23h43l ]]9E]28<F*8*F'Eui{MM#t"D 
JJ>J" E1b!D"%1b!aa  

DIIK 4<DHqVA:HQK &'1!A$$'%%f-	tDQi  T"XQ/0ID	4IJSPI!WFMM%qjMM% iFT4!eAh?td{**6/*JKY  MM#' (s   >I1c                    \        V P                  V P                  R R7      p\        V P                  VP
                  ^,           4      pV P                  pVf5   \        P                  P                  VP                  4      w  rEVR,           p\        VR4      ;_uu_ 4       p\        P                  \        P                  ,          pV P                  '       d   V\        P                  ,          pV P                   '       d   V\        P                  ,          pV P"                  '       d   V\        P$                  ,          pR\&        R\(        R\*        /pV FY  p	W^,
          ,          p
WP,                  ,          ! V
VV P.                  V P0                  V P2                  V P4                  VR7       K[  	  RRR4       R#   + '       g   i     R# ; i)	Fr   Nz.txtr   simpler  layoutr  )r9   rt   r4   rl   r   rz   r   ru   rv   splitextr2   r,   r   TEXT_PRESERVE_LIGATURESTEXT_PRESERVE_WHITESPACEconvert_whitenoligaturesextra_spacesTEXT_INHIBIT_SPACESr  r   r  modegridr  r  r  )r   r!   r   r   r3   r   r  r  funcr   r  s   &          r   gettextr  &  sK   
DJJ5
9CTZZ!!34E[[F~gg&&sxx0F"	fd		w//'2R2RRW555EW444EW000Eknk

 CQw<DO		  
			s   "A G (G ,B
G  G	c                 ^    \         P                  ! R 4       \         P                  ! R4       R# )zThis is from PyMuPDF message().zThis is from PyMuPDF log().N)r   r   log)r   s   &r   	_internalr  G  s    OO56KK-.r   c                    \         P                  ! R\        R4      R7      p V P                  RRR7      pVP	                  R\        R4      R	7      pVP                  R
\        RR7       VP                  RRR7       VP                  RRRR7       VP                  RRRR7       VP                  RRRR7       VP                  R\        RR7       VP                  R\        RR7       VP                  \        R7       VP	                  R\        R4      R	7      pVP                  R
\        RR7       VP                  R\        R R7       VP                  RRR7       VP                  R!R"RR#R$7       VP                  R%\        R&R7       VP                  R'\        R(R7       VP                  R)\        R*\        ^4      ^ R+7       VP                  R,RR-R.R/7       VP                  R0RR-R1R/7       VP                  R2RR-R3R/7       VP                  R4\        RR5R67       VP                  R7RR-R8R/7       VP                  R9RR-R:R/7       VP                  RR;R7       VP                  \        R7       VP	                  R<\        R=4      R>R?7      pVP                  R
R@RARB7       VP                  RCRDRERF7       VP                  \        R7       VP	                  RG\        RH4      R	7      pVP                  R
\        RR7       VP                  RIRRJR7       VP                  RKRRLR7       VP                  RCRMR7       VP                  RRR7       VP                  R\        RNR7       VP                  \        R7       VP	                  RO\        RP4      R	7      pVP                  R
RR7       VP                  RQRRR7       VP                  RSRRTR7       VP                  RRR7       VP                  \        R7       VP	                  RU\        RV4      R	7      pVP                  R
RR7       VP                  RRR7       VP                  RCRWR7       VP                  RQRDRXRF7       VP                  RYRDRZRF7       VP                  R[R\R7       VP                  \        R7       VP	                  R]\        R^4      R	7      pVP                  R
RR7       VP                  RRR7       VP                  RCRWR7       VP                  RQRDR_RF7       VP                  \         R7       VP	                  R`\        Ra4      RbR?7      pVP                  R
RR7       VP                  RQRDRcRF7       VP                  RRR7       VP                  RCRdR7       VP                  RYReR7       VP                  RfRgR7       VP                  RhRiR7       VP                  R[RjR7       VP                  \"        R7       VP	                  Rk\        Rl4      R	7      p	V	P                  R
\        RR7       V	P                  RQRDRcRF7       V	P                  RRR7       V	P                  RmR-RRnRo7       V	P                  RCRpR7       V	P                  \$        R7       VP	                  Rq\        Rr4      R	7      p
V
P                  R
\        RsR7       V
P                  RRtR7       V
P                  RCRuR7       V
P                  RvRDRwRF7       V
P                  RxRyR7       V
P                  RQR@RzRB7       V
P                  \&        R7       VP	                  R{\        R|4      R	7      pVP                  R
\        R}R7       VP                  RR~R7       VP                  R\        RRRR+7       VP                  R\        RRR7       VP                  RRRR-R7       VP                  RRRR-R7       VP                  RRRR-R7       VP                  RRRR-R7       VP                  RRRR-R7       VP                  RCRR7       VP                  R\(        R^R7       VP                  R\(        R^R7       VP                  \*        R7       VP	                  R\        R4      R	7      pVP                  \,        R7       V P/                  4       p\1        VR4      '       g   V P3                  4        R# VP5                  V4       R# )zDefine command configurations.r   zBasic PyMuPDF Functions)progdescriptionSubcommandsz/Enter 'command -h' for subcommand specific help)titlehelpr5   zdisplay PDF information)r  rt   zPDF filename)r   r  z	-passwordr4   )r  z-catalog
store_truezshow PDF catalog)actionr  z-trailerzshow PDF trailerz	-metadatazshow PDF metadataz-xrefsz&show selected objects, format: 1,5-7,Nz-pagesz'show selected pages, format: 1,5-7,50-N)r  r   z.optimize PDF, or create sub-PDF if pages givenr   zoutput PDF filenamez-encryptionzencryption methodr   )r  choicesdefaultz-ownerzowner passwordz-userzuser passwordz-garbagezgarbage collection level)r   r  r  r  z	-compressFzcompress (deflate) output)r  r  r  z-asciizASCII encode binary dataz-linearzformat for fast web displayz-permissionzinteger with permission levels)r   r  r  z	-sanitizezsanitize / clean contentsz-prettyzprettify PDF structurez/output selected pages pages, format: 1,5-7,50-Nr   zjoin PDF documentsz3specify each input as 'filename[,password[,pages]]')r  epilog*zinput filenames)nargsr  z-outputTzoutput filename)requiredr  extractz extract images and fonts to diskz-imageszextract imagesz-fontszextract fontsz-folder to receive output, defaults to currentz-consider these pages only, format: 1,5-7,50-Nz
embed-infozlist embedded filesz-namezif given, report only this onez-detailzdetail informationz	embed-addzadd embedded filez-output PDF filename, incremental save if nonezname of new entryz-pathzpath to data for new entryz-desczdescription of new entryz	embed-delzdelete embedded filezname of entry to deletez	embed-updzupdate embedded filez*except '-name' all parameters are optionalzname of entryz-Output PDF filename, incremental save if nonezpath to new data for entryz	-filenameznew filename to store in entryz
-ufilenamez&new unicode filename to store in entryz!new description to store in entryzembed-extractzextract embedded file to diskz-unsafezPallow write to stored name even if an existing file or outside current directory)r  r  r  z'output filename, default is stored namez
embed-copyz copy embedded files between PDFszPDF to receive embedded fileszpassword of inputz2output PDF, incremental save to 'input' if omittedz-sourcezcopy embedded files from herez
-pwdsourcezpassword of 'source' PDFzrestrict copy to these entriesr  z(extract text in various formatting modeszinput document filenamezpassword for input documentz-modez-mode: simple, block sort, or layout (default)r  z select pages, format: 1,5-7,50-Nz1-N)r   r  r  z-noligaturesz*expand ligature characters (default False))r  r  r  z-convert-whitez6convert whitespace characters to white (default False)z-extra-spacesz%fill gaps with spaces (default False)z-noformfeedz-write linefeeds, no formfeeds (default False)z-skip-emptyz+suppress pages with no text (default False)z3store text in this file (default inputfilename.txt)z-gridz+merge lines if closer than this (default 2)z	-fontsizez4only include text with a larger fontsize (default 3)internalzinternal testingr  Nr   r+   )r  r  r  )argparseArgumentParserr   add_subparsers
add_parseradd_argumentr[   set_defaultsr5   r_   rb   r   r   r   r   r   r   r   r   r   floatr  r  
parse_argshasattr
print_helpr  )parsersubpsps_showps_cleanps_join
ps_extractps_embed_addps_embed_delps_embed_updps_embed_extractps_embed_copy
ps_gettextps_internalr   s                 r   mainr  K  s$
   $$67F !!"S " E v8<U3VWGs@:6L?QRL?QR\@STs!I   s!J   d#
 X&VW   H '.A(3HI+J7 K	   (3CD'/B'a   (	   u;U   *	   C2R   (	   ,<T   H   u%
 12D  G
 2CDT8IJh'
 !!x(JK " J G#NCIlAQRH\PG   Kj9s!P   1
 (+@"A  G ~6'GH<>RS:6m,
 ##*=!> $ L gN;k
;G   g;NOg;WXg,FG<0
 ##*@!A $ L gN;k
;G   g;TU<0
 ##34; $ L
 gN;g?Kk
;G   g,HIk0PQC   g,OP<0
 ''X.M%N (  !!'.!I!!'D!O!!+J!?!!)U<_ "  !!A "  !!|!4
 $$(+M"N % M wS7VW{1DEL   D'F   |2LMs!A   M2
 !!x(RS " J G#4MNK.KL<.   /	   9	   E	   4	   <	   :	   B   :	   C	   )
 ""); < # K ),
 D4  		$r   __main__)FT)r  )"r  r*  ru   r.   r{  typingr   r   r   rY   r   r   r&   r9   rE   rV   rl   r5   r   r   r   r   r   r   r   r   r   r  r   r  r  r  r  __name__r  r   r   <module>r     s      	 
  " " &!H,.,^<~,^*%P&*D/d"J?D	^BB/rj	 zF r   