# Path: confopy/pdfextract/pdfminer_wrapper.py
# class PDFMinerWrapper:
#     """ Wrapper for pdfminer package functionality """
# 
#     def __init__(self):
#         pass
# 
#     def pdf2txt(self, filename, options=Options()):
#         result = ""
#         with open(filename, "rb") as fp:
#             conv = _PDFMiner(options)
#             result = conv.to_txt(fp)
#         return result
# 
#     def pdf2html(self, filename, options=Options()):
#         result = ""
#         with open(filename, "rb") as fp:
#             conv = _PDFMiner(options)
#             result = conv.to_html(fp)
#         return result
# 
#     def pdf2xml(self, filename, options=Options()):
#         result = ""
#         with open(filename, "rb") as fp:
#             conv = _PDFMiner(options)
#             result = conv.to_xml(fp)
#         return result
# 
# Path: confopy/pdfextract/pdfminer_xml_bindings.py
# def DOM2pages(dom_document):
#     dom_pages = dom_document.getElementsByTagName("page")
#     # Forget about multiprocessing here.
#     # DOM objects seems to have some side effects not allowing this.
#     return map(DOM2page, dom_pages)
# 
# Path: confopy/pdfextract/heuristics.py
# class HeuristicManager(object):
#     """HeuristicManager"""
#     def __init__(self):
#         super(HeuristicManager, self).__init__()
#         self.heuristics = list()
# 
#         self.heuristics.append(SimpleDocumentHeuristic())
# 
#     def generate_document(self, dom_pages):
#         hints = self._apply_heuristics(dom_pages)
#         return self._build_document_hierarchy(dom_pages, hints)
# 
#     def _apply_heuristics(self, dom_pages):
#         hints = dict()
#         for heu in self.heuristics:
#             hints = heu.apply(pages=dom_pages, hints=hints)
#         return hints
# 
#     def _build_document_hierarchy(self, dom_pages, hints):
#         root = Document()
#         node = root # current node to add children to
#         last_title = u""
#         accu_heading_nr = None
# 
#         for p in dom_pages:
#             pagenr = unicode(p.ID)
#             for tb in p.textboxes:
#                 tb_kind = hints.get(tb, TextBoxType.NONE)
#                 #print str(tb_kind) + " words: " + str(tb.word_count)
#                 #tb._print()
# 
#                 if tb_kind == TextBoxType.HEADING:
#                     title = lines2unicode(tb.lines, True, u"\n")
#                     sec = Section(title=title, pagenr=pagenr)
#                     relation = HeuristicRegExes.compare_sections(last_title, title)
#                     if relation is not HeuristicRegExes.ERROR_SECTION_RELATION:
#                         node.add_child(sec, relation)
#                     else:
#                         node.add_child(sec)
#                     node = sec
#                     last_title = title
# 
#                 elif tb_kind == TextBoxType.HEADING_PART_NUMBER:
#                     accu_heading_nr = tb
#                 elif tb_kind == TextBoxType.HEADING_PART_HEADING:
#                     if accu_heading_nr:
#                         title=lines2unicode(tb.lines, True, u"\n")
#                         number=lines2unicode(accu_heading_nr.lines, True, u"\n")
#                         sec = Section(title=title, number=number, pagenr=pagenr)
#                         relation = HeuristicRegExes.compare_sections(last_title, number)
#                         if relation is not HeuristicRegExes.ERROR_SECTION_RELATION:
#                             node.add_child(sec, relation)
#                         else:
#                             node.add_child(sec)
#                         node = sec
#                         last_title = number
#                         accu_heading_nr = None
# 
#                 elif tb_kind == TextBoxType.FOOTNOTE:
#                     node.add_child(Footnote(text=lines2unicode(tb.lines, True, u"\n"), pagenr=pagenr))
#                 elif tb_kind == TextBoxType.PARAGRAPH:
#                     font = unicode(tb.font[0])
#                     fontsize = unicode(tb.font[1])
#                     emph = [unicode(e) for e in tb.emph]
#                     node.add_child(Paragraph(text=lines2unicode(tb.lines, True, u"\n"), pagenr=pagenr, font=font, fontsize=fontsize, emph=emph))
#                 elif tb_kind == TextBoxType.PARAGRAPH_WITH_HEADING:
#                     heading_line_count = lines_using(tb.lines, tb.emph, True)
#                     heading_lines = tb.lines[:heading_line_count]
#                     paragraph_lines = tb.lines[heading_line_count:]
#                     title = lines2unicode(heading_lines, True, u"\n")
#                     sec = Section(title=title, pagenr=pagenr)
#                     relation = HeuristicRegExes.compare_sections(last_title, title)
#                     if relation is not HeuristicRegExes.ERROR_SECTION_RELATION:
#                         node.add_child(sec, relation)
#                     else:
#                         node.add_child(sec)
#                     node = sec
#                     last_title = title
#                     font = unicode(tb.font[0])
#                     fontsize = unicode(tb.font[1])
#                     emph = [unicode(e) for e in tb.emph]
#                     node.add_child(Paragraph(text=lines2unicode(paragraph_lines, True, u"\n"), pagenr=pagenr, font=font, fontsize=fontsize, emph=emph))
# 
#                 elif TextBoxType.is_float(tb_kind):
#                     node.add_child(Float(text=lines2unicode(tb.lines, True, u"\n"), pagenr=pagenr))
# 
#         doc_check = DocumentChecker()
#         return doc_check.cleanup(root)


from xml.dom.minidom import parseString
from confopy.pdfextract.pdfminer_wrapper import PDFMinerWrapper
from confopy.pdfextract.pdfminer_xml_bindings import DOM2pages
from confopy.pdfextract.heuristics import HeuristicManager
# coding: utf-8
'''
File: convenience.py
Author: Oliver Zscheyge
Description:
    Convenience functions for handling PDF conversions.
'''




def PDF2XMLstring(filepath):

# Path: confopy/pdfextract/pdfminer_wrapper.py
# class PDFMinerWrapper:
#     """ Wrapper for pdfminer package functionality """
# 
#     def __init__(self):
#         pass
# 
#     def pdf2txt(self, filename, options=Options()):
#         result = ""
#         with open(filename, "rb") as fp:
#             conv = _PDFMiner(options)
#             result = conv.to_txt(fp)
#         return result
# 
#     def pdf2html(self, filename, options=Options()):
#         result = ""
#         with open(filename, "rb") as fp:
#             conv = _PDFMiner(options)
#             result = conv.to_html(fp)
#         return result
# 
#     def pdf2xml(self, filename, options=Options()):
#         result = ""
#         with open(filename, "rb") as fp:
#             conv = _PDFMiner(options)
#             result = conv.to_xml(fp)
#         return result
# 
# Path: confopy/pdfextract/pdfminer_xml_bindings.py
# def DOM2pages(dom_document):
#     dom_pages = dom_document.getElementsByTagName("page")
#     # Forget about multiprocessing here.
#     # DOM objects seems to have some side effects not allowing this.
#     return map(DOM2page, dom_pages)
# 
# Path: confopy/pdfextract/heuristics.py
# class HeuristicManager(object):
#     """HeuristicManager"""
#     def __init__(self):
#         super(HeuristicManager, self).__init__()
#         self.heuristics = list()
# 
#         self.heuristics.append(SimpleDocumentHeuristic())
# 
#     def generate_document(self, dom_pages):
#         hints = self._apply_heuristics(dom_pages)
#         return self._build_document_hierarchy(dom_pages, hints)
# 
#     def _apply_heuristics(self, dom_pages):
#         hints = dict()
#         for heu in self.heuristics:
#             hints = heu.apply(pages=dom_pages, hints=hints)
#         return hints
# 
#     def _build_document_hierarchy(self, dom_pages, hints):
#         root = Document()
#         node = root # current node to add children to
#         last_title = u""
#         accu_heading_nr = None
# 
#         for p in dom_pages:
#             pagenr = unicode(p.ID)
#             for tb in p.textboxes:
#                 tb_kind = hints.get(tb, TextBoxType.NONE)
#                 #print str(tb_kind) + " words: " + str(tb.word_count)
#                 #tb._print()
# 
#                 if tb_kind == TextBoxType.HEADING:
#                     title = lines2unicode(tb.lines, True, u"\n")
#                     sec = Section(title=title, pagenr=pagenr)
#                     relation = HeuristicRegExes.compare_sections(last_title, title)
#                     if relation is not HeuristicRegExes.ERROR_SECTION_RELATION:
#                         node.add_child(sec, relation)
#                     else:
#                         node.add_child(sec)
#                     node = sec
#                     last_title = title
# 
#                 elif tb_kind == TextBoxType.HEADING_PART_NUMBER:
#                     accu_heading_nr = tb
#                 elif tb_kind == TextBoxType.HEADING_PART_HEADING:
#                     if accu_heading_nr:
#                         title=lines2unicode(tb.lines, True, u"\n")
#                         number=lines2unicode(accu_heading_nr.lines, True, u"\n")
#                         sec = Section(title=title, number=number, pagenr=pagenr)
#                         relation = HeuristicRegExes.compare_sections(last_title, number)
#                         if relation is not HeuristicRegExes.ERROR_SECTION_RELATION:
#                             node.add_child(sec, relation)
#                         else:
#                             node.add_child(sec)
#                         node = sec
#                         last_title = number
#                         accu_heading_nr = None
# 
#                 elif tb_kind == TextBoxType.FOOTNOTE:
#                     node.add_child(Footnote(text=lines2unicode(tb.lines, True, u"\n"), pagenr=pagenr))
#                 elif tb_kind == TextBoxType.PARAGRAPH:
#                     font = unicode(tb.font[0])
#                     fontsize = unicode(tb.font[1])
#                     emph = [unicode(e) for e in tb.emph]
#                     node.add_child(Paragraph(text=lines2unicode(tb.lines, True, u"\n"), pagenr=pagenr, font=font, fontsize=fontsize, emph=emph))
#                 elif tb_kind == TextBoxType.PARAGRAPH_WITH_HEADING:
#                     heading_line_count = lines_using(tb.lines, tb.emph, True)
#                     heading_lines = tb.lines[:heading_line_count]
#                     paragraph_lines = tb.lines[heading_line_count:]
#                     title = lines2unicode(heading_lines, True, u"\n")
#                     sec = Section(title=title, pagenr=pagenr)
#                     relation = HeuristicRegExes.compare_sections(last_title, title)
#                     if relation is not HeuristicRegExes.ERROR_SECTION_RELATION:
#                         node.add_child(sec, relation)
#                     else:
#                         node.add_child(sec)
#                     node = sec
#                     last_title = title
#                     font = unicode(tb.font[0])
#                     fontsize = unicode(tb.font[1])
#                     emph = [unicode(e) for e in tb.emph]
#                     node.add_child(Paragraph(text=lines2unicode(paragraph_lines, True, u"\n"), pagenr=pagenr, font=font, fontsize=fontsize, emph=emph))
# 
#                 elif TextBoxType.is_float(tb_kind):
#                     node.add_child(Float(text=lines2unicode(tb.lines, True, u"\n"), pagenr=pagenr))
# 
#         doc_check = DocumentChecker()
#         return doc_check.cleanup(root)


# Path: confopy/pdfextract/convenience.py
from xml.dom.minidom import parseString
from confopy.pdfextract.pdfminer_wrapper import PDFMinerWrapper
from confopy.pdfextract.pdfminer_xml_bindings import DOM2pages
from confopy.pdfextract.heuristics import HeuristicManager

# coding: utf-8
'''
File: convenience.py
Author: Oliver Zscheyge
Description:
    Convenience functions for handling PDF conversions.
'''




def PDF2XMLstring(filepath):

    pdfminer = PDFMinerWrapper()