parent
44b223cf0a
commit
33b16b3f07
|
@ -5,6 +5,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|||
|
||||
## [Unreleased]
|
||||
|
||||
### Deprecated
|
||||
- The argument `_py2_no_more_posargs` because Python2 is removed on January
|
||||
, 2020 ([#328](https://github.com/pdfminer/pdfminer.six/pull/328) and
|
||||
[#307](https://github.com/pdfminer/pdfminer.six/pull/307))
|
||||
|
||||
### Added
|
||||
- Support for extracting JBIG2 encoded images ([#311](https://github.com/pdfminer/pdfminer.six/pull/311) and [#46](https://github.com/pdfminer/pdfminer.six/pull/46))
|
||||
|
||||
|
|
|
@ -18,11 +18,10 @@ from .image import ImageWriter
|
|||
|
||||
|
||||
def extract_text_to_fp(inf, outfp,
|
||||
_py2_no_more_posargs=None, # Bloody Python2 needs a shim
|
||||
output_type='text', codec='utf-8', laparams = None,
|
||||
maxpages=0, page_numbers=None, password="", scale=1.0, rotation=0,
|
||||
layoutmode='normal', output_dir=None, strip_control=False,
|
||||
debug=False, disable_caching=False, **other):
|
||||
debug=False, disable_caching=False, **kwargs):
|
||||
"""
|
||||
Parses text from inf-file and writes to outfp file-like object.
|
||||
Takes loads of optional arguments but the defaults are somewhat sane.
|
||||
|
@ -44,6 +43,13 @@ def extract_text_to_fp(inf, outfp,
|
|||
debug: Output more logging data
|
||||
disable_caching: Does what it says on the tin
|
||||
"""
|
||||
if '_py2_no_more_posargs' in kwargs is not None:
|
||||
raise DeprecationWarning(
|
||||
'The `_py2_no_more_posargs will be removed on January, 2020. At '
|
||||
'that moment pdfminer.six will stop supporting Python 2. Please '
|
||||
'upgrade to Python 3. For more information see '
|
||||
'https://github.com/pdfminer/pdfminer .six/issues/194')
|
||||
|
||||
if six.PY2 and sys.stdin.encoding:
|
||||
password = password.decode(sys.stdin.encoding)
|
||||
|
||||
|
|
|
@ -15,15 +15,19 @@ from pdfminer.image import ImageWriter
|
|||
|
||||
|
||||
def extract_text(files=[], outfile='-',
|
||||
_py2_no_more_posargs=None, # Bloody Python2 needs a shim
|
||||
no_laparams=False, all_texts=None, detect_vertical=None, # LAParams
|
||||
word_margin=None, char_margin=None, line_margin=None, boxes_flow=None, # LAParams
|
||||
output_type='text', codec='utf-8', strip_control=False,
|
||||
maxpages=0, page_numbers=None, password="", scale=1.0, rotation=0,
|
||||
layoutmode='normal', output_dir=None, debug=False,
|
||||
disable_caching=False, **other):
|
||||
if _py2_no_more_posargs is not None:
|
||||
raise ValueError("Too many positional arguments passed.")
|
||||
disable_caching=False, **kwargs):
|
||||
if '_py2_no_more_posargs' in kwargs is not None:
|
||||
raise DeprecationWarning(
|
||||
'The `_py2_no_more_posargs will be removed on January, 2020. At '
|
||||
'that moment pdfminer.six will stop supporting Python 2. Please '
|
||||
'upgrade to Python 3. For more information see '
|
||||
'https://github.com/pdfminer/pdfminer .six/issues/194')
|
||||
|
||||
if not files:
|
||||
raise ValueError("Must provide files to work upon!")
|
||||
|
||||
|
|
|
@ -11,28 +11,32 @@ pdfminer.settings.STRICT = False
|
|||
import pdfminer.high_level
|
||||
import pdfminer.layout
|
||||
|
||||
def compare(file1,file2,**args):
|
||||
if args.get('_py2_no_more_posargs',None) is not None:
|
||||
raise ValueError("Too many positional arguments passed.")
|
||||
|
||||
def compare(file1, file2, **kwargs):
|
||||
if '_py2_no_more_posargs' in kwargs is not None:
|
||||
raise DeprecationWarning(
|
||||
'The `_py2_no_more_posargs will be removed on January, 2020. At '
|
||||
'that moment pdfminer.six will stop supporting Python 2. Please '
|
||||
'upgrade to Python 3. For more information see '
|
||||
'https://github.com/pdfminer/pdfminer .six/issues/194')
|
||||
|
||||
# If any LAParams group arguments were passed, create an LAParams object and
|
||||
# populate with given args. Otherwise, set it to None.
|
||||
if args.get('laparams',None) is None:
|
||||
if kwargs.get('laparams', None) is None:
|
||||
laparams = pdfminer.layout.LAParams()
|
||||
for param in ("all_texts", "detect_vertical", "word_margin", "char_margin", "line_margin", "boxes_flow"):
|
||||
paramv = args.get(param, None)
|
||||
paramv = kwargs.get(param, None)
|
||||
if paramv is not None:
|
||||
laparams[param]=paramv
|
||||
args['laparams']=laparams
|
||||
kwargs['laparams']=laparams
|
||||
|
||||
s1=six.StringIO()
|
||||
with open(file1, "rb") as fp:
|
||||
pdfminer.high_level.extract_text_to_fp(fp,s1, **args)
|
||||
pdfminer.high_level.extract_text_to_fp(fp, s1, **kwargs)
|
||||
|
||||
s2=six.StringIO()
|
||||
with open(file2, "rb") as fp:
|
||||
pdfminer.high_level.extract_text_to_fp(fp,s2, **args)
|
||||
pdfminer.high_level.extract_text_to_fp(fp, s2, **kwargs)
|
||||
|
||||
import difflib
|
||||
s1.seek(0)
|
||||
|
@ -41,12 +45,12 @@ def compare(file1,file2,**args):
|
|||
|
||||
import os.path
|
||||
try:
|
||||
extension = os.path.splitext(args['outfile'])[1][1:4]
|
||||
extension = os.path.splitext(kwargs['outfile'])[1][1:4]
|
||||
if extension.lower()=='htm':
|
||||
return difflib.HtmlDiff().make_file(s1,s2)
|
||||
except KeyError:
|
||||
pass
|
||||
return difflib.unified_diff(s1,s2,n=args['context_lines'])
|
||||
return difflib.unified_diff(s1, s2, n=kwargs['context_lines'])
|
||||
|
||||
|
||||
# main
|
||||
|
|
Loading…
Reference in New Issue