#!/usr/bin/env python
#_*_coding: utf-8_*_
import sys, re
def Find(patt, text):
match = re.findall(patt, text)
if match:
for block in match:
if '/Type /Page\n' in block:
print (block + '-----------------')
else : print ('Не найдено...')
f = open(sys.argv[1], 'r')
data = f.read()
patt = re.compile(r'\sobj([\s\S]+?)endobj')
Find(patt, data)
[console]$ ./pdfparser.py test.pdf[/console]
Показать
<<
/Resources 3 0 R
/Type /Page
/MediaBox [0 0 595.275 841.889]
/CropBox [0 0 595.275 841.889]
/BleedBox [0 0 595.275 841.889]
/TrimBox [0 0 595.275 841.889]
/Parent 1 0 R
/Contents 16 0 R
>>
-----------------
<<
/Resources 3 0 R
/Type /Page
/MediaBox [0 0 595.275 841.889]
/CropBox [0 0 595.275 841.889]
/BleedBox [0 0 595.275 841.889]
/TrimBox [0 0 595.275 841.889]
/Parent 1 0 R
/Contents 19 0 R
>>
-----------------
<<
/Resources 3 0 R
/Type /Page
/MediaBox [0 0 595.275 841.889]
/CropBox [0 0 595.275 841.889]
/BleedBox [0 0 595.275 841.889]
/TrimBox [0 0 595.275 841.889]
/Parent 1 0 R
/Annots 24 0 R
/Contents 26 0 R
>>
-----------------
<<
/Resources 3 0 R
/Type /Page
/MediaBox [0 0 595.275 841.889]
/CropBox [0 0 595.275 841.889]
/BleedBox [0 0 595.275 841.889]
/TrimBox [0 0 595.275 841.889]
/Parent 1 0 R
/Contents 29 0 R
>>
-----------------
<<
/Resources 3 0 R
/Type /Page
/MediaBox [0 0 595.275 841.889]
/CropBox [0 0 595.275 841.889]
/BleedBox [0 0 595.275 841.889]
/TrimBox [0 0 595.275 841.889]
/Parent 1 0 R
/Contents 32 0 R
>>
-----------------
<<
/Resources 3 0 R
/Type /Page
/MediaBox [0 0 595.275 841.889]
/CropBox [0 0 595.275 841.889]
/BleedBox [0 0 595.275 841.889]
/TrimBox [0 0 595.275 841.889]
/Parent 1 0 R
/Contents 35 0 R
>>
-----------------
<<
/Resources 3 0 R
/Type /Page
/MediaBox [0 0 595.275 841.889]
/CropBox [0 0 595.275 841.889]
/BleedBox [0 0 595.275 841.889]
/TrimBox [0 0 595.275 841.889]
/Parent 1 0 R
/Annots 40 0 R
/Contents 42 0 R
>>
-----------------
<<
/Resources 3 0 R
/Type /Page
/MediaBox [0 0 595.275 841.889]
/CropBox [0 0 595.275 841.889]
/BleedBox [0 0 595.275 841.889]
/TrimBox [0 0 595.275 841.889]
/Parent 1 0 R
/Contents 45 0 R
>>
-----------------
<<
/Resources 3 0 R
/Type /Page
/MediaBox [0 0 595.275 841.889]
/CropBox [0 0 595.275 841.889]
/BleedBox [0 0 595.275 841.889]
/TrimBox [0 0 595.275 841.889]
/Parent 1 0 R
/Contents 48 0 R
>>
-----------------
<<
/Resources 3 0 R
/Type /Page
/MediaBox [0 0 595.275 841.889]
/CropBox [0 0 595.275 841.889]
/BleedBox [0 0 595.275 841.889]
/TrimBox [0 0 595.275 841.889]
/Parent 1 0 R
/Annots 53 0 R
/Contents 54 0 R
>>
-----------------
<<
/Resources 3 0 R
/Type /Page
/MediaBox [0 0 595.275 841.889]
/CropBox [0 0 595.275 841.889]
/BleedBox [0 0 595.275 841.889]
/TrimBox [0 0 595.275 841.889]
/Parent 1 0 R
/Contents 57 0 R
>>
-----------------
<<
/Resources 3 0 R
/Type /Page
/MediaBox [0 0 595.275 841.889]
/CropBox [0 0 595.275 841.889]
/BleedBox [0 0 595.275 841.889]
/TrimBox [0 0 595.275 841.889]
/Parent 1 0 R
/Contents 60 0 R
>>
-----------------
<<
/Resources 3 0 R
/Type /Page
/MediaBox [0 0 595.275 841.889]
/CropBox [0 0 595.275 841.889]
/BleedBox [0 0 595.275 841.889]
/TrimBox [0 0 595.275 841.889]
/Parent 1 0 R
/Contents 63 0 R
>>
-----------------
<<
/Resources 3 0 R
/Type /Page
/MediaBox [0 0 595.275 841.889]
/CropBox [0 0 595.275 841.889]
/BleedBox [0 0 595.275 841.889]
/TrimBox [0 0 595.275 841.889]
/Parent 1 0 R
/Contents 66 0 R
>>
-----------------
<<
/Resources 3 0 R
/Type /Page
/MediaBox [0 0 595.275 841.889]
/CropBox [0 0 595.275 841.889]
/BleedBox [0 0 595.275 841.889]
/TrimBox [0 0 595.275 841.889]
/Parent 1 0 R
/Contents 69 0 R
>>
-----------------
<<
/Resources 3 0 R
/Type /Page
/MediaBox [0 0 595.275 841.889]
/CropBox [0 0 595.275 841.889]
/BleedBox [0 0 595.275 841.889]
/TrimBox [0 0 595.275 841.889]
/Parent 1 0 R
/Contents 72 0 R
>>
-----------------
<<
/Resources 3 0 R
/Type /Page
/MediaBox [0 0 595.275 841.889]
/CropBox [0 0 595.275 841.889]
/BleedBox [0 0 595.275 841.889]
/TrimBox [0 0 595.275 841.889]
/Parent 1 0 R
/Contents 75 0 R
>>
-----------------
<<
/Resources 3 0 R
/Type /Page
/MediaBox [0 0 595.275 841.889]
/CropBox [0 0 595.275 841.889]
/BleedBox [0 0 595.275 841.889]
/TrimBox [0 0 595.275 841.889]
/Parent 1 0 R
/Contents 78 0 R
>>
-----------------
<<
/Resources 3 0 R
/Type /Page
/MediaBox [0 0 595.275 841.889]
/CropBox [0 0 595.275 841.889]
/BleedBox [0 0 595.275 841.889]
/TrimBox [0 0 595.275 841.889]
/Parent 1 0 R
/Contents 81 0 R
>>
-----------------
Оно ?