[Python] How to extract internal links using PyPDF

Discussão em 'Python' iniciado por Stack, Dezembro 20, 2024.

  1. Stack

    Stack Membro Participativo

    Got this far with PyPDF, trying to extract internal links:

    import pypdf

    internal_links = []
    with open(<pdf_path>, 'rb') as pdf_file:
    reader = pypdf.PdfReader(pdf_file)
    for page_num in range(len(reader.pages)):
    page = reader.pages[page_num]
    if "/Annots" in page:
    for annot in page["/Annots"]:
    annot_obj = annot.get_object()
    if annot_obj["/Subtype"] == "/Link":
    if "/Dest" in annot_obj:
    dest = annot_obj["/Dest"]
    print(f"page: {page_num} dest: {dest}")


    but can't figure out how to get the page number from dest. Looked in the pypdf codebase and also in the returned object, but still stuck. Any help appreciated :)

    Continue reading...

Compartilhe esta Página