I'm trying to extract the text from PDF by subjects.
in order to do so im trying to identify the labels \ headlines in the PDF.
So far I have converted the PDF into xml file, in order to get the text data more easily, and then using the font \ size of each in to deiced if a line is a label or not.
the main problem with this way, is that each PDF can have its own build, and not necessarily what works for one PDF will work for the other.
I will be glad if someone have an idea how to overcome this problem so that it will be possible to extract the labels (text by subjects) without depending on the PDF (most of the PDFs I work with are articles \ books)
different ways to extract text by subjects also welcome.
(As the tag indicates, I'm trying to do this in Python)
Edit:
At the moment im doing 2 things:

check font of each line
check each line text size

i concluded that: regular text will have the most lines with its font (there are more than x10 lines with this font than all other texts), and that if you look at the median of text size, it will be the size of the regular text.
From the first i can remove all regular text, and from the second i can take all texts that are bigger and all the labels will be in this list.
The problem now is to extract only the labels from this list since usually there is text that is bigger than the regular text yet isn't a label.
I tried to use the amount of time each fonts shows in the text to identify the labels fonts, but without much success. For each PDF the amount can vary.
I'm looking for ideas how to solve this problem, or if someone know a tools that can do it more easily.
I would suggest studying many pdfs and write down every pdf label text size. Then, you can average the top 5 highest fonts and average the top 5 lowest fonts. Now, you can make a range between them and check text if it is in that text size range. 
This method will not work always, but, will cover the majority of pdfs.
(The more pdfs you study the better)
Extracting PDF text by subjects