Skip to content

Retrieve all the versions of a PDF when saved incrementally #3092

Closed

Description

@3051360

I've observed that PyMuPDF provides functionality to determine the number of versions present in a document.

Currently, I'm utilizing pdfresurrect, a C tool/library designed to "extract older 'hidden' versions of a PDF from the current PDF."

While my larger application is built using PyMuPDF, I have to call the compiled C code through Python for version retrieval, which is not an ideal way of building applications.

I propose that enhancing the capability to retrieve all PDF version files directly within PyMuPDF would be beneficial.

Activity

  1. cipri-tom commented on Jan 24, 2024

    @cipri-tom

    Here's how I do it:

            pattern = re.compile(b'[^t]xref.*?EOF', flags=re.M+re.S)
    
            # `inc_nb` means the number of incremental update contained in the binary
            matches = list(pattern.finditer(doc.data))
            inc_nb = len(matches)
            if not inc_nb > 1:
                return result
    
            # here we loop to separate each incremental update in
            # the binary to retrieve each version of the file
            # We don't take into account the current version
            for sub in matches[:-1]:
                stream = doc.data[:sub.span()[1]] # binary code of a version
                if not stream:
                    continue
                previous = Doc(stream).as_fitz() # is one of the previous version of the file
  2. JorjMcKie commented on Jan 25, 2024

    @JorjMcKie
    Collaborator

    This feature would have to be implemented by our base library MuPDF to make any sense.
    Currently, you can find out the number of versions of a PDF: doc.version_count only.

    Please talk to the MuPDF colleagues on e.g. their Dicscord channel about options they may see.

  3. locked and limited conversation to collaborators on Jan 25, 2024
  4. converted this issue into a discussion #3096 on Jan 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions