Exemple #1
0
def getTocFromPdf(pdf, shift=0, default=None, baselvl=0, child_cnt=0):
    ch = _getDestinationPageNumbers(pdf)
    if ch == None:
        return []
    ch.sort(key=lambda x: x[1:3])
    ch = [[decodeForSure(x[0]), x[1]+shift, x[2]+baselvl] for x in ch]
    for i in range(len(ch)):
        j = k = 0
        while i+j+1 < len(ch) and ch[i+j+1][2] > ch[i][2]:
            k += 1 if ch[i+j+1][2] == ch[i][2]+1 else 0
            j += 1
        ch[i].append(k)
    if len(ch) == 0 and default != None:
        ch.append([default, 1+shift, baselvl, child_cnt])
    return ch
Exemple #2
0
def _uniconvHex(s):
    out = ""
    s = decodeForSure(s)
    for c in s:
        out += str(hex(ord(c)))[2:].upper().rjust(4, "0")
    return out