better handling of ligatures: fixes #58

This commit is contained in:
fritz-hh
2014-01-13 23:13:15 +01:00
parent a872ce751d
commit e40f1fa081
4 changed files with 15 additions and 22 deletions
-1
View File
@@ -46,7 +46,6 @@ Usage: OCRmyPDF.sh [-h] [-v] [-g] [-k] [-d] [-c] [-i] [-o dpi] [-f] [-l languag
-C : Pass an additional configuration file to the tesseract OCR engine.
(this option can be used more than once)
Note 1: The configuration file must be available in the "tessdata/configs" folder of your tesseract installation
Note 2: The folder "./tess-cfg" contains useful tesseract configuration files
inputfile : PDF file to be OCRed
outputfile : The PDF/A file that will be generated
--------------------------------------------------------------------------------------
+15
View File
@@ -1,4 +1,5 @@
#!/usr/local/bin/python2
# coding: utf-8
##############################################################################
# Copyright (c) 2013-14: fritz-hh from Github (https://github.com/fritz-hh)
#
@@ -171,6 +172,17 @@ class hocrTransform():
"""
return float(pxl)/self.dpi*inch
def replace_unsupported_chars(self, str):
"""
Given an input string, returns the corresponding string that:
- is available in the helvetica facetype
- does not contain any ligature (to allow easy search in the PDF file)
"""
# The 'u' before the character to replace indicates that it is a unicode character
str=str.replace(u"","fl")
str=str.replace(u"","fi")
return str
def to_pdf(self, outFileName, imageFileName, showBoundingboxes, fontname="Helvetica"):
"""
Creates a PDF file with an image superimposed on top of the text.
@@ -217,6 +229,9 @@ class hocrTransform():
for elem in self.hocr.findall(".//%sspan[@class='%s']" % (self.xmlns, elemclass)):
elemtxt=self._get_element_text(elem).rstrip()
elemtxt=self.replace_unsupported_chars(elemtxt)
if len(elemtxt) == 0:
continue
-12
View File
@@ -1,12 +0,0 @@
##############################################################################
# Readme
#
# Copyright (c) 2013-14: fritz-hh from Github (https://github.com/fritz-hh)
##############################################################################
The file(s) located in this folder are tesseract configuration files.
(Tesseract configuration files enable to tune the behaviour of tesseract)
If needed, these files should be copied to the "tessdata/configs" folder of your tesseract installation.
To request OCRmyPDF.sh to use a configuration file, please use the -C option
-9
View File
@@ -1,9 +0,0 @@
##############################################################################
# tesseract config file provided for OCRmyPDF
#
# prevents tesseract to detect ligatures, as ligatures are not displayed correctly in the final PDF file
# but are replaced by a black square
#
# Copyright (c) 2013-14: fritz-hh from Github (https://github.com/fritz-hh)
##############################################################################
tessedit_char_blacklist fifl