I would like to split individual PDF documents from a compound set from a file. So far it works for files which are structured: %PDF- .... %%EOF ... %PDF- .... %%EOF by using the following code:
REGEX_PDF = b'%PDF\-.+?%%EOF'
pdfDocuments = re.findall( REGEX_PDF, fileContent, re.DOTALL )
Now I need to change the software to also work with PDFs with extensions. This results in a file structure like this: %PDF- .... %%EOF ... %%EOF ... %%EOF ... %PDF- .... %%EOF. So I need to match to substrings from a PDF tag until the last %%EOF tag before the next PDF tag. My best guess is this:
REGEX_PDF = b'%PDF\-.+(?!%PDF\-).+%%EOF'
But it does not seem to work. Instead only 1 substring is matched from the 1st %PDF tag top the very last %%EOF tag. Does someone has an idea where the error is?
Thanks in advance, Thomas