+
    i!                         R t ^ RIHtHt ^ RIHtHt ^RIHt ^RI	H
t
 ^RIHtHtHtHtHt R R ltR R	 ltR
 R ltR R ltR R ltR R ltR R ltR R ltR R ltR# )u  
Page labels are shown by PDF viewers as "the page number".

A page has a numeric index, starting at 0. Additionally, the page
has a label. In the most simple case:

    label = index + 1

However, the title page and the table of contents might have Roman numerals as
page labels. This makes things more complicated.

Example 1
---------

>>> reader.root_object["/PageLabels"]["/Nums"]
[0, IndirectObject(18, 0, 139929798197504),
 8, IndirectObject(19, 0, 139929798197504)]
>>> reader.get_object(reader.root_object["/PageLabels"]["/Nums"][1])
{'/S': '/r'}
>>> reader.get_object(reader.root_object["/PageLabels"]["/Nums"][3])
{'/S': '/D'}

Example 2
---------
The following is a document with pages labeled
i, ii, iii, iv, 1, 2, 3, A-8, A-9, ...

1 0 obj
    << /Type /Catalog
       /PageLabels << /Nums [
                        0 << /S /r >>
                        4 << /S /D >>
                        7 << /S /D
                             /P ( A- )
                             /St 8
                        >>
                        % A number tree containing
                        % three page label dictionaries
                        ]
                   >>
    ...
    >>
endobj


§12.4.2 PDF Specification 1.7 and 2.0
=====================================

Entries in a page label dictionary
----------------------------------
The /S key:
D       Decimal Arabic numerals
R       Uppercase Roman numerals
r       Lowercase Roman numerals
A       Uppercase letters (A to Z for the first 26 pages,
                           AA to ZZ for the next 26, and so on)
a       Lowercase letters (a to z for the first 26 pages,
                           aa to zz for the next 26, and so on)
)CallableIterator)Optionalcast)PdfCommonDocProtocol)logger_warning)ArrayObjectDictionaryObject
NullObjectNumberObjectis_null_or_nonec                0    V ^8  d   QhR\         R\        /#    numreturnintstr)formats   "X/Users/agent/.openclaw/workspace/venv/lib/python3.14/site-packages/pypdf/_page_labels.py__annotate__r   K   s     ) ) ) )    c                 ^   a . ROoR V3R llpRP                  \        V! V 4      4      4      # )  c                F    V ^8  d   QhR\         R\        \        ,          /# r   )r   r   r   )r   s   "r   r   4number2uppercase_roman_numeral.<locals>.__annotate__\   s      s x} r   c              3      <"   S F5  w  r\        W4      w  r4W#,          x  WV,          ,          p V ^ 8:  g   K4   R# 	  R# 5i)    N)divmod)r   decimal
roman_reprx_romans   &    r   	roman_num1number2uppercase_roman_numeral.<locals>.roman_num\   s=     #(G#'DA. Q;Cax $)s
   2AA ))r   M)i  CM)i  D)i  CD)d   C)Z   XC)2   L)(   XL)
   X)	   IX)   V)   IV)   I)joinlist)r   r%   r$   s   & @r   number2uppercase_roman_numeralr@   K   s.    E   774	#'((r   c                0    V ^8  d   QhR\         R\        /# r   numberr   r   )r   s   "r   r   r   g   s     : :3 :3 :r   c                 4    \        V 4      P                  4       # N)r@   lowerrC   s   &r   number2lowercase_roman_numeralrH   g   s    )&17799r   c                0    V ^8  d   QhR\         R\        /# rB   r   )r   s   "r   r   r   k   s      C C r   c                 6   V ^ 8:  d   \        R4      h\        \        R4      \        R4      ^,           4       Uu. uF  p\        V4      NK  	  ppRpV ^ 8  d<   V ^,          pV^ 8X  d   ^pW$^,
          ,          V,           pW,          p V ^,          p KB  V# u upi )r   zExpecting a positive numberAZr'   )
ValueErrorrangeordchr)rC   ialphabetrep	remainders   &    r   number2uppercase_letterrU   k   s    {677 %c#hC1 => =1A =H>
C
1*RK	>I1}%+2J ?s   Bc                0    V ^8  d   QhR\         R\        /# rB   r   )r   s   "r   r   r   {   s     3 3C 3C 3r   c                 4    \        V 4      P                  4       # rE   )rU   rF   rG   s   &r   number2lowercase_letterrX   {   s    "6*0022r   c                <    V ^8  d   QhR\         R\        R\        /# )r   dictionary_objectindexr   )r	   r   r   )r   s   "r   r   r      s'     "B "B+; "BC "BC "Br   c                 X   \        \        V R ,          4      p^ pRp^ pV\        V4      8  d^   W#,          pW#^,           ,          P                  4       pV^,           \        V4      8X  d   M W#^,           ,          V8  d   MV^,          pKm  RR R\        R\
        R\        R\        R\        /p\        V\        4      '       g   \	        V^,           4      # VP                  R^4      pVP                  R	R
4      pWdP                  R4      ,          p	W! W,
          V,           4      ,           # )/NumsNc                     R # )r'    )r#   s   &r   <lambda>%get_label_from_nums.<locals>.<lambda>   s    r   z/Dz/Rz/rz/Az/az/Stz/Pr'   z/S)r   r   len
get_objectr   r@   rH   rU   rX   
isinstancedictget)
rZ   r[   numsrQ   valuestart_indexmstartprefixmapping_functions
   &&        r   get_label_from_numsrn      s    .w78D	AEK
c$i-gU&&(q5CIA;	Qlc,,%%4A eT""519~IIeQEYYtR F4)$U%85%@AAAr   c                <    V ^8  d   QhR\         R\        R\        /# )r   readerr[   r   )r   r   r   )r   s   "r   r   r      s"     . ., .S .S .r   c                   \        \        V P                  4      pRV9  d   \        V^,           4      # \        \        VR,          P	                  4       4      pRV9   d   \        W14      # RV9   d   \        VR,          \        4      '       g   ^ pV^d8  d   \        \        \        ,          VR,          4      pV F  p\        \        \        ,          VR,          4      pV^ ,          Tu;8:  d   V^,          8:  g   KD  M KH  \        VP                  RR4      4      '       g!   V^,          pV^d8X  d   \        R4      hTp K  \        Wa4      u # 	   \        RV R2\        4       \        V^,           4      # )	z
See 7.9.7 "Number Trees".

Args:
    reader: The PdfReader
    index: The index of the page

Returns:
    The label of the page, e.g. "iv" or "4".

z/PageLabelsr]   z/Kidsz/LimitsNz"Too deep nesting is not supported.z,Could not reliably determine page label for .)r   r	   root_objectr   rc   rn   rd   r
   r?   r   r   rf   NotImplementedErrorr   __name__)rp   r[   rootnumber_treelevelkidskidlimitss   &&      r   index2labelr|      sC     &"4"45DD 519~'m)<)G)G)IJK+";66+jW1Ez&R&R ck-.G0DEDd3iY8!9222*3777D+ABB
 C<"5 D#  '* .s:: & A%JHUuqy>r   c                @    V ^8  d   QhR\         R\        R\        RR/# )r   keyrh   rg   r   N)r   r	   r   )r   s   "r   r   r      s0     " "	"" " 
	"r   c                T   \        V4      ^,          ^ 8w  d   \        R4      h\        V4      pV^ 8w  d    WV^,
          ,          8:  d   V^,
          pK&  V\        V4      8  d   WV,          8X  d   WV^,           &   R# VP                  W04       VP                  V^,           V4       R# )z
Insert a key, value pair in a Nums array.

See 7.9.7 "Number Trees".

Args:
    key: number key of the entry
    value: value of the entry
    nums: Nums array to modify

6A nums like array must have an even number of elementsN)rb   rM   insert)r~   rh   rg   rQ   s   &&& r   nums_insertr      s      4y1}QRRD	A
q&SQK'E3t9}QQUAAE5!r   c                @    V ^8  d   QhR\         R\        R\        RR/# )r   r~   page_index_torg   r   N)r   r   r   )r   s   "r   r   r      s0      	  
	r   c                "   \        V4      ^,          ^ 8w  d   \        R4      hW8  d   \        R4      hVP                  V 4      ^,           pV\        V4      8  d4   W#,          V8:  d%   VP                  V4       VP                  V4       KA  R# R# )z
Remove all entries in a number tree in a range after an entry.

See 7.9.7 "Number Trees".

Args:
    key: number key of the entry before the range
    page_index_to: The page index of the upper limit of the range
    nums: Nums array to modify

r   z/page_index_to must be greater or equal than keyN)rb   rM   r[   pop)r~   r   rg   rQ   s   &&& r   nums_clear_ranger      su      4y1}QRRJKK

3!A
c$i-DG}4 5-r   c          	          V ^8  d   QhR\         R\        R\        \        \         ,          \        \        ,          3,          /# )r   r~   rg   r   )r   r   tupler   r	   )r   s   "r   r   r     s;      	
 8L!8,<#==>r   c                    \        V4      ^,          ^ 8w  d   \        R4      hVP                  V 4      ^,           pV\        V4      8  d   W,          W^,           ,          3# R# )z
Return the (key, value) pair of the entry after the given one.

See 7.9.7 "Number Trees".

Args:
    key: number key of the entry
    nums: Nums array

r   )NN)rb   rM   r[   )r~   rg   rQ   s   && r   	nums_nextr     sV     4y1}QRR

3!A3t9}!e%%r   N)__doc__collections.abcr   r   typingr   r   
_protocolsr   _utilsr   genericr   r	   r
   r   r   r@   rH   rU   rX   rn   r|   r   r   r   r_   r   r   <module>r      sS   :x / ! , " )8: 3"BJ.b"<6r   