The code snippet below grew out of a proof of concept for reading data from Austrian land register extracts (German: Grundbuchauszug). In detail, the goal was to automatically capture the owners’ data, including their shares, and then store it in a database. Since Austrian land register extracts are issued as plain PDFs, the difficulty lies in reading the data correctly. In the PoC this was implemented with a few splits, a check whether special characters or spaces follow, and a few other tricks. The code will not win a beauty contest, but the desired functions could be implemented.
You can find the updated version of the land register extract parser here.
You will find the Python code below.
from pdfminer.pdfinterp import PDFResourceManager, PDFPageInterpreter
from pdfminer.converter import TextConverter
from pdfminer.layout import LAParams
from pdfminer.pdfpage import PDFPage
from io import StringIO
from pprint import pprint
def convert_pdf_to_txt(path):
rsrcmgr = PDFResourceManager()
retstr = StringIO()
codec = 'utf-8'
laparams = LAParams()
device = TextConverter(rsrcmgr, retstr, codec=codec, laparams=laparams)
fp = open(path, 'rb')
interpreter = PDFPageInterpreter(rsrcmgr, device)
password = ""
maxpages = 0
caching = True
pagenos = set()
for page in PDFPage.get_pages(fp, pagenos, maxpages=maxpages, password=password,caching=caching, check_extractable=True):
interpreter.process_page(page)
text = retstr.getvalue()
fp.close()
device.close()
retstr.close()
return text
def cleanup_pdf_text(text):
output = []
for line in text:
if line != '':
output.append(line)
return output
pdf_text = cleanup_pdf_text(convert_pdf_to_txt('pdf/GB.pdf').split('\n'))
print(pdf_text)
output = {}
output['anteile'] = {}
temp_output = {}
current_stage = ''
current_substage = ''
current_substage_share = ''
current_substage_part = ''
current_substage_number = ''
for pdf_line in pdf_text:
if 'Seite' in pdf_line:
continue
if '*** B ***' in pdf_line:
current_stage = 'anteile'
if current_stage == 'anteile':
print(pdf_line)
if 'ANTEIL' in pdf_line:
print('------------------------------ Found new Anteil')
current_substage_number = pdf_line.split('ANTEIL:')[0].strip().split(' ')[0].strip()
print(current_substage_number)
current_substage_share = pdf_line.split('ANTEIL:')[1].split('/')[0].strip()
output['total_shares'] = pdf_line.split('ANTEIL:')[1].split('/')[1].strip()
current_substage_part = 'anteilig'
continue
# next line is name of owner
if current_substage_part == 'anteilig':
current_substage_name = pdf_line.strip()
temp_output = {}
temp_output['share'] = current_substage_share
temp_output['name'] = pdf_line.strip()
temp_output['firstname'] = pdf_line.strip().split(' ')[-2]
temp_output['lastname'] = pdf_line.strip().split(' ')[-1]
if len(pdf_line.strip().split(' ')) > 2:
temp_output['title'] = pdf_line.strip().split(' ')[0]
else:
temp_output['title'] = ''
temp_output['family'] = '0'
current_substage_part = 'anteilig-name'
continue
# next line is birthdate and address
if current_substage_part == 'anteilig-name':
print(pdf_line)
address = pdf_line.split('ADR:')[1]
address_with_country = address[:len(address) - 4].strip()
if ',' in address_with_country:
temp_output['address'] = address_with_country.split(',')[0].strip()
temp_output['city'] = address_with_country.split(',')[1].strip()
else:
temp_output['address'] = address_with_country.strip()
temp_output['postal_code'] = address[-4:].strip()
current_substage_part = 'anteil_detail'
continue
if current_substage_part == 'anteil_detail':
if 'Wohnungseigentum an' in pdf_line:
temp_output['apartment'] = pdf_line.split('Wohnungseigentum an')[1].strip()
# we need to find out if the current apartment is already stored in our output array, if not we append
# if found we add a marker called family which indicates that more then one person owns given aparment
add_to_output = True
if len(output['anteile']) > 0:
for index, item in output['anteile'].items():
if item['apartment'] == temp_output['apartment']:
output['anteile'][index]['family'] = 1
if 'family_members' not in output['anteile'][index]:
output['anteile'][index]['family_members'] = []
output['anteile'][index]['family_members'].append(temp_output)
add_to_output = False
if add_to_output is True:
output['anteile'][current_substage_number] = temp_output
current_substage_part = 'finished'
pprint(output)
The code stores the data from the respective land register extract as a Python array. The data can then be output in any format you like. If you are interested in further development of the functionality shown here, feel free to get in touch.
Below you will find a demo output to illustrate the data structure.

Since this is a proof of concept, there are of course still a few rough edges. As far as I remember, the title of a person is still displayed incorrectly from time to time, especially for double names, so this is a spot that would need improvement. Basically, though, everything should work. You can specify your land register PDF file in line 45. Currently the script assumes that the land register extract is located in the “pdf” folder and named “GB.pdf”.
Of course, I cannot guarantee that the extracted data will be processed without errors, so you use the code and the data generated from it at your own risk!
Would you rather have this as a finished tool in the browser than as a script, with upload, checks and export for the whole team? I build solutions like that as a custom web app.




