0

I'm implementing some parsing algorithm and for that I need to convert pdfs into html and I picked pdf2htmlEX for this purpose. I want to parse data on basis of headings and paragraphs.

The pdf2HTMLEx library works great in terms of UX, but the HTML text produced is full of <span> and <div> tags and might result difficult to understand as it is not very much readable neither it includes any heading tags etc.

Like this:

1. The model of perfect competition is more useful for analy <span class="_ _0"> <span>zing situations in which firms <span class="_ _1"></span> </div><div class="t m0 x5 h2 y35 ff2 fs1 fc0 sc0 ls1 ws0">a. engage in price wars in order to secure a position in the market  </div>

My questions are:

  1. How can I separate each heading along with their paragraphs out of it?
  2. Is there any way to do it using pdf2htmlEX?
0

I tried the same for parsing bank statements. What worked best for me wasn't to conver to HTML but to convert the output to XML.

Surprisingly, you can use the same command:

pdftohtml -s -xml -enc "UTF-8" <infile> <outfile>

I however used the standard (Linux) version of pdftohtml. I don't know whether or not the variant you are using is fully backward compatible.

  • I took your advise and used xml format but a bit lost in their parsing algorithm as my file contains text tags only <page number="1" position="absolute" top="0" left="0" height="1188" width="918"><fontspec id="0" size="12" family="Times" color="#000000"/> Page1</text><text top="1133" left="864" width="3" height="15" font="0"> </text><text top="81" left="54" width="259" height="25" font="1">Arslan Ahmad </text><text top="118" left="53" width="5" height="17" font="2"> </text> something like this. Can you elaborate more how can I extract headings with their paras out of it? – Falcon Feb 27 '17 at 10:32
  • From your sample it seems that the XML includes a lot of meta-data It shows <page> and <text> elements defining fonts. These can be filtered out. That allows you to focus on the actual data you are looking for. I parsed the XML in Python using xml.etree.ElementTree and some regular expressions to find the data I was looking for. – NZD Feb 28 '17 at 5:14
  • Yes, I'm also using python and cElementTree but I don't think so regex can be a help here for me as I want to parse on basis of headings and want to make chunks of document. So, I'm trying to put many if conds on basis of font sizes but yet again every person uses different font sizes so I'm first sorting out font sizes and declaring largest and second largest fonts as headings but that is not a smart approach as second largest font can be a heading or cannot be sometimes. What do you think? – Falcon Feb 28 '17 at 7:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.