2016-11-08 19:01:11 +00:00
|
|
|
|
2014-06-26 09:12:39 +00:00
|
|
|
from .pdffont import PDFUnicodeNotDefined
|
2009-07-23 14:03:58 +00:00
|
|
|
|
Many changes to make pdf2txt.py work better in Py3, some in that script, others in module!
Sorry, changes should have been more atomic.
*In pdf2txt.py:*
* Re-wrote main function to use argparse instead of optparse.
* Manually tested in Py2/Py3 to get partial consistency.
* Errors abound including Tags mode, but most modes weren't working at all in Py3 anyway.
* Py2 mode *probably* unchanged, cannot find any bugs yet...
* Kept old main function for posterity, for now.
*In utils:*
* Added a few compatibility functions (some string hax required chardet, new dependency):
- make_compat_bytes(in_str)-> (py3->bytes | py2->str)
- make_compat_str(in_str)-> (str)
- compatible_encode_method(bytesorstring, encoding, erraction)-> (str)
*In pdfdevice:*
* To handle different output filetypes in Py3, injected lots of calls to new utils methods,
as well as some six.PYX checks and logic. These changes are largely responsible for
enhanced Py2/Py3 consistency.
*In converter:*
* To handle output filetypes in Py2, injected a few checks and fixes particularly around the
py2 `str.encode` method and its *assumed* usual use-analogies in Py3.
2015-05-17 20:08:57 +00:00
|
|
|
from . import utils
|
2009-07-23 14:03:58 +00:00
|
|
|
|
2009-01-10 09:14:46 +00:00
|
|
|
## PDFDevice
|
|
|
|
##
|
|
|
|
class PDFDevice(object):
|
|
|
|
|
2010-04-24 04:32:03 +00:00
|
|
|
def __init__(self, rsrcmgr):
|
|
|
|
self.rsrcmgr = rsrcmgr
|
2009-10-24 04:41:59 +00:00
|
|
|
self.ctm = None
|
|
|
|
return
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
return '<PDFDevice>'
|
|
|
|
|
2017-08-18 06:15:04 +00:00
|
|
|
def __enter__(self):
|
|
|
|
return self
|
|
|
|
|
|
|
|
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
|
|
self.close()
|
|
|
|
|
2009-10-24 04:41:59 +00:00
|
|
|
def close(self):
|
|
|
|
return
|
|
|
|
|
|
|
|
def set_ctm(self, ctm):
|
|
|
|
self.ctm = ctm
|
|
|
|
return
|
|
|
|
|
|
|
|
def begin_tag(self, tag, props=None):
|
|
|
|
return
|
2013-11-07 08:35:04 +00:00
|
|
|
|
2009-10-24 04:41:59 +00:00
|
|
|
def end_tag(self):
|
|
|
|
return
|
2013-11-07 08:35:04 +00:00
|
|
|
|
2009-10-24 04:41:59 +00:00
|
|
|
def do_tag(self, tag, props=None):
|
|
|
|
return
|
|
|
|
|
|
|
|
def begin_page(self, page, ctm):
|
|
|
|
return
|
2013-11-07 08:35:04 +00:00
|
|
|
|
2009-10-24 04:41:59 +00:00
|
|
|
def end_page(self, page):
|
|
|
|
return
|
2013-11-07 08:35:04 +00:00
|
|
|
|
2009-10-24 04:41:59 +00:00
|
|
|
def begin_figure(self, name, bbox, matrix):
|
|
|
|
return
|
2013-11-07 08:35:04 +00:00
|
|
|
|
2009-10-24 04:41:59 +00:00
|
|
|
def end_figure(self, name):
|
|
|
|
return
|
|
|
|
|
|
|
|
def paint_path(self, graphicstate, stroke, fill, evenodd, path):
|
|
|
|
return
|
2013-11-07 08:35:04 +00:00
|
|
|
|
2010-01-30 07:30:01 +00:00
|
|
|
def render_image(self, name, stream):
|
2009-10-24 04:41:59 +00:00
|
|
|
return
|
2013-11-07 08:35:04 +00:00
|
|
|
|
2009-10-24 04:41:59 +00:00
|
|
|
def render_string(self, textstate, seq):
|
|
|
|
return
|
2009-07-23 14:03:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
## PDFTextDevice
|
|
|
|
##
|
|
|
|
class PDFTextDevice(PDFDevice):
|
|
|
|
|
2009-10-24 04:41:59 +00:00
|
|
|
def render_string(self, textstate, seq):
|
Many changes to make pdf2txt.py work better in Py3, some in that script, others in module!
Sorry, changes should have been more atomic.
*In pdf2txt.py:*
* Re-wrote main function to use argparse instead of optparse.
* Manually tested in Py2/Py3 to get partial consistency.
* Errors abound including Tags mode, but most modes weren't working at all in Py3 anyway.
* Py2 mode *probably* unchanged, cannot find any bugs yet...
* Kept old main function for posterity, for now.
*In utils:*
* Added a few compatibility functions (some string hax required chardet, new dependency):
- make_compat_bytes(in_str)-> (py3->bytes | py2->str)
- make_compat_str(in_str)-> (str)
- compatible_encode_method(bytesorstring, encoding, erraction)-> (str)
*In pdfdevice:*
* To handle different output filetypes in Py3, injected lots of calls to new utils methods,
as well as some six.PYX checks and logic. These changes are largely responsible for
enhanced Py2/Py3 consistency.
*In converter:*
* To handle output filetypes in Py2, injected a few checks and fixes particularly around the
py2 `str.encode` method and its *assumed* usual use-analogies in Py3.
2015-05-17 20:08:57 +00:00
|
|
|
matrix = utils.mult_matrix(textstate.matrix, self.ctm)
|
2009-10-24 04:41:59 +00:00
|
|
|
font = textstate.font
|
|
|
|
fontsize = textstate.fontsize
|
|
|
|
scaling = textstate.scaling * .01
|
|
|
|
charspace = textstate.charspace * scaling
|
|
|
|
wordspace = textstate.wordspace * scaling
|
2010-05-18 14:57:04 +00:00
|
|
|
rise = textstate.rise
|
2010-02-13 15:00:43 +00:00
|
|
|
if font.is_multibyte():
|
|
|
|
wordspace = 0
|
2009-10-24 04:41:59 +00:00
|
|
|
dxscale = .001 * fontsize * scaling
|
2010-02-13 15:00:43 +00:00
|
|
|
if font.is_vertical():
|
|
|
|
textstate.linematrix = self.render_string_vertical(
|
2010-05-18 14:57:04 +00:00
|
|
|
seq, matrix, textstate.linematrix, font, fontsize,
|
|
|
|
scaling, charspace, wordspace, rise, dxscale)
|
2010-02-13 15:00:43 +00:00
|
|
|
else:
|
|
|
|
textstate.linematrix = self.render_string_horizontal(
|
2010-05-18 14:57:04 +00:00
|
|
|
seq, matrix, textstate.linematrix, font, fontsize,
|
|
|
|
scaling, charspace, wordspace, rise, dxscale)
|
2010-02-13 15:00:43 +00:00
|
|
|
return
|
2013-11-07 07:14:53 +00:00
|
|
|
|
2014-06-15 03:12:13 +00:00
|
|
|
def render_string_horizontal(self, seq, matrix, pos,
|
2010-05-18 14:57:04 +00:00
|
|
|
font, fontsize, scaling, charspace, wordspace, rise, dxscale):
|
2014-06-15 03:12:13 +00:00
|
|
|
(x, y) = pos
|
2010-02-27 03:59:25 +00:00
|
|
|
needcharspace = False
|
2009-10-24 04:41:59 +00:00
|
|
|
for obj in seq:
|
Many changes to make pdf2txt.py work better in Py3, some in that script, others in module!
Sorry, changes should have been more atomic.
*In pdf2txt.py:*
* Re-wrote main function to use argparse instead of optparse.
* Manually tested in Py2/Py3 to get partial consistency.
* Errors abound including Tags mode, but most modes weren't working at all in Py3 anyway.
* Py2 mode *probably* unchanged, cannot find any bugs yet...
* Kept old main function for posterity, for now.
*In utils:*
* Added a few compatibility functions (some string hax required chardet, new dependency):
- make_compat_bytes(in_str)-> (py3->bytes | py2->str)
- make_compat_str(in_str)-> (str)
- compatible_encode_method(bytesorstring, encoding, erraction)-> (str)
*In pdfdevice:*
* To handle different output filetypes in Py3, injected lots of calls to new utils methods,
as well as some six.PYX checks and logic. These changes are largely responsible for
enhanced Py2/Py3 consistency.
*In converter:*
* To handle output filetypes in Py2, injected a few checks and fixes particularly around the
py2 `str.encode` method and its *assumed* usual use-analogies in Py3.
2015-05-17 20:08:57 +00:00
|
|
|
if utils.isnumber(obj):
|
2010-02-27 03:59:25 +00:00
|
|
|
x -= obj*dxscale
|
2010-03-22 08:36:39 +00:00
|
|
|
needcharspace = True
|
2009-10-24 04:41:59 +00:00
|
|
|
else:
|
|
|
|
for cid in font.decode(obj):
|
2010-02-27 03:59:25 +00:00
|
|
|
if needcharspace:
|
|
|
|
x += charspace
|
Many changes to make pdf2txt.py work better in Py3, some in that script, others in module!
Sorry, changes should have been more atomic.
*In pdf2txt.py:*
* Re-wrote main function to use argparse instead of optparse.
* Manually tested in Py2/Py3 to get partial consistency.
* Errors abound including Tags mode, but most modes weren't working at all in Py3 anyway.
* Py2 mode *probably* unchanged, cannot find any bugs yet...
* Kept old main function for posterity, for now.
*In utils:*
* Added a few compatibility functions (some string hax required chardet, new dependency):
- make_compat_bytes(in_str)-> (py3->bytes | py2->str)
- make_compat_str(in_str)-> (str)
- compatible_encode_method(bytesorstring, encoding, erraction)-> (str)
*In pdfdevice:*
* To handle different output filetypes in Py3, injected lots of calls to new utils methods,
as well as some six.PYX checks and logic. These changes are largely responsible for
enhanced Py2/Py3 consistency.
*In converter:*
* To handle output filetypes in Py2, injected a few checks and fixes particularly around the
py2 `str.encode` method and its *assumed* usual use-analogies in Py3.
2015-05-17 20:08:57 +00:00
|
|
|
x += self.render_char(utils.translate_matrix(matrix, (x, y)),
|
2010-05-18 14:57:04 +00:00
|
|
|
font, fontsize, scaling, rise, cid)
|
2010-02-13 15:00:43 +00:00
|
|
|
if cid == 32 and wordspace:
|
2010-02-27 03:59:25 +00:00
|
|
|
x += wordspace
|
2010-03-22 08:36:39 +00:00
|
|
|
needcharspace = True
|
2010-02-13 15:00:43 +00:00
|
|
|
return (x, y)
|
|
|
|
|
2014-06-15 03:12:13 +00:00
|
|
|
def render_string_vertical(self, seq, matrix, pos,
|
2010-05-18 14:57:04 +00:00
|
|
|
font, fontsize, scaling, charspace, wordspace, rise, dxscale):
|
2014-06-15 03:12:13 +00:00
|
|
|
(x, y) = pos
|
2010-02-27 03:59:25 +00:00
|
|
|
needcharspace = False
|
2010-02-13 15:00:43 +00:00
|
|
|
for obj in seq:
|
Many changes to make pdf2txt.py work better in Py3, some in that script, others in module!
Sorry, changes should have been more atomic.
*In pdf2txt.py:*
* Re-wrote main function to use argparse instead of optparse.
* Manually tested in Py2/Py3 to get partial consistency.
* Errors abound including Tags mode, but most modes weren't working at all in Py3 anyway.
* Py2 mode *probably* unchanged, cannot find any bugs yet...
* Kept old main function for posterity, for now.
*In utils:*
* Added a few compatibility functions (some string hax required chardet, new dependency):
- make_compat_bytes(in_str)-> (py3->bytes | py2->str)
- make_compat_str(in_str)-> (str)
- compatible_encode_method(bytesorstring, encoding, erraction)-> (str)
*In pdfdevice:*
* To handle different output filetypes in Py3, injected lots of calls to new utils methods,
as well as some six.PYX checks and logic. These changes are largely responsible for
enhanced Py2/Py3 consistency.
*In converter:*
* To handle output filetypes in Py2, injected a few checks and fixes particularly around the
py2 `str.encode` method and its *assumed* usual use-analogies in Py3.
2015-05-17 20:08:57 +00:00
|
|
|
if utils.isnumber(obj):
|
2010-02-27 03:59:25 +00:00
|
|
|
y -= obj*dxscale
|
2010-03-22 08:36:39 +00:00
|
|
|
needcharspace = True
|
2010-02-13 15:00:43 +00:00
|
|
|
else:
|
|
|
|
for cid in font.decode(obj):
|
2010-02-27 03:59:25 +00:00
|
|
|
if needcharspace:
|
|
|
|
y += charspace
|
Many changes to make pdf2txt.py work better in Py3, some in that script, others in module!
Sorry, changes should have been more atomic.
*In pdf2txt.py:*
* Re-wrote main function to use argparse instead of optparse.
* Manually tested in Py2/Py3 to get partial consistency.
* Errors abound including Tags mode, but most modes weren't working at all in Py3 anyway.
* Py2 mode *probably* unchanged, cannot find any bugs yet...
* Kept old main function for posterity, for now.
*In utils:*
* Added a few compatibility functions (some string hax required chardet, new dependency):
- make_compat_bytes(in_str)-> (py3->bytes | py2->str)
- make_compat_str(in_str)-> (str)
- compatible_encode_method(bytesorstring, encoding, erraction)-> (str)
*In pdfdevice:*
* To handle different output filetypes in Py3, injected lots of calls to new utils methods,
as well as some six.PYX checks and logic. These changes are largely responsible for
enhanced Py2/Py3 consistency.
*In converter:*
* To handle output filetypes in Py2, injected a few checks and fixes particularly around the
py2 `str.encode` method and its *assumed* usual use-analogies in Py3.
2015-05-17 20:08:57 +00:00
|
|
|
y += self.render_char(utils.translate_matrix(matrix, (x, y)),
|
2010-05-18 14:57:04 +00:00
|
|
|
font, fontsize, scaling, rise, cid)
|
2010-02-13 15:00:43 +00:00
|
|
|
if cid == 32 and wordspace:
|
2010-02-27 03:59:25 +00:00
|
|
|
y += wordspace
|
2010-03-22 08:36:39 +00:00
|
|
|
needcharspace = True
|
2010-02-13 15:00:43 +00:00
|
|
|
return (x, y)
|
2010-02-27 03:59:25 +00:00
|
|
|
|
2010-05-18 14:57:04 +00:00
|
|
|
def render_char(self, matrix, font, fontsize, scaling, rise, cid):
|
2010-02-27 03:59:25 +00:00
|
|
|
return 0
|
2010-04-24 13:31:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
## TagExtractor
|
|
|
|
##
|
|
|
|
class TagExtractor(PDFDevice):
|
|
|
|
|
2014-06-14 06:43:10 +00:00
|
|
|
def __init__(self, rsrcmgr, outfp, codec='utf-8'):
|
2010-04-24 13:31:11 +00:00
|
|
|
PDFDevice.__init__(self, rsrcmgr)
|
|
|
|
self.outfp = outfp
|
|
|
|
self.codec = codec
|
|
|
|
self.pageno = 0
|
2011-02-14 13:51:20 +00:00
|
|
|
self._stack = []
|
2010-04-24 13:31:11 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
def render_string(self, textstate, seq):
|
|
|
|
font = textstate.font
|
|
|
|
text = ''
|
|
|
|
for obj in seq:
|
Many changes to make pdf2txt.py work better in Py3, some in that script, others in module!
Sorry, changes should have been more atomic.
*In pdf2txt.py:*
* Re-wrote main function to use argparse instead of optparse.
* Manually tested in Py2/Py3 to get partial consistency.
* Errors abound including Tags mode, but most modes weren't working at all in Py3 anyway.
* Py2 mode *probably* unchanged, cannot find any bugs yet...
* Kept old main function for posterity, for now.
*In utils:*
* Added a few compatibility functions (some string hax required chardet, new dependency):
- make_compat_bytes(in_str)-> (py3->bytes | py2->str)
- make_compat_str(in_str)-> (str)
- compatible_encode_method(bytesorstring, encoding, erraction)-> (str)
*In pdfdevice:*
* To handle different output filetypes in Py3, injected lots of calls to new utils methods,
as well as some six.PYX checks and logic. These changes are largely responsible for
enhanced Py2/Py3 consistency.
*In converter:*
* To handle output filetypes in Py2, injected a few checks and fixes particularly around the
py2 `str.encode` method and its *assumed* usual use-analogies in Py3.
2015-05-17 20:08:57 +00:00
|
|
|
obj = utils.make_compat_str(obj)
|
2013-11-07 08:35:04 +00:00
|
|
|
if not isinstance(obj, str):
|
|
|
|
continue
|
2010-04-24 13:31:11 +00:00
|
|
|
chars = font.decode(obj)
|
|
|
|
for cid in chars:
|
|
|
|
try:
|
|
|
|
char = font.to_unichr(cid)
|
|
|
|
text += char
|
|
|
|
except PDFUnicodeNotDefined:
|
Many changes to make pdf2txt.py work better in Py3, some in that script, others in module!
Sorry, changes should have been more atomic.
*In pdf2txt.py:*
* Re-wrote main function to use argparse instead of optparse.
* Manually tested in Py2/Py3 to get partial consistency.
* Errors abound including Tags mode, but most modes weren't working at all in Py3 anyway.
* Py2 mode *probably* unchanged, cannot find any bugs yet...
* Kept old main function for posterity, for now.
*In utils:*
* Added a few compatibility functions (some string hax required chardet, new dependency):
- make_compat_bytes(in_str)-> (py3->bytes | py2->str)
- make_compat_str(in_str)-> (str)
- compatible_encode_method(bytesorstring, encoding, erraction)-> (str)
*In pdfdevice:*
* To handle different output filetypes in Py3, injected lots of calls to new utils methods,
as well as some six.PYX checks and logic. These changes are largely responsible for
enhanced Py2/Py3 consistency.
*In converter:*
* To handle output filetypes in Py2, injected a few checks and fixes particularly around the
py2 `str.encode` method and its *assumed* usual use-analogies in Py3.
2015-05-17 20:08:57 +00:00
|
|
|
print(chars)
|
2010-04-24 13:31:11 +00:00
|
|
|
pass
|
Many changes to make pdf2txt.py work better in Py3, some in that script, others in module!
Sorry, changes should have been more atomic.
*In pdf2txt.py:*
* Re-wrote main function to use argparse instead of optparse.
* Manually tested in Py2/Py3 to get partial consistency.
* Errors abound including Tags mode, but most modes weren't working at all in Py3 anyway.
* Py2 mode *probably* unchanged, cannot find any bugs yet...
* Kept old main function for posterity, for now.
*In utils:*
* Added a few compatibility functions (some string hax required chardet, new dependency):
- make_compat_bytes(in_str)-> (py3->bytes | py2->str)
- make_compat_str(in_str)-> (str)
- compatible_encode_method(bytesorstring, encoding, erraction)-> (str)
*In pdfdevice:*
* To handle different output filetypes in Py3, injected lots of calls to new utils methods,
as well as some six.PYX checks and logic. These changes are largely responsible for
enhanced Py2/Py3 consistency.
*In converter:*
* To handle output filetypes in Py2, injected a few checks and fixes particularly around the
py2 `str.encode` method and its *assumed* usual use-analogies in Py3.
2015-05-17 20:08:57 +00:00
|
|
|
self.outfp.write(utils.enc(text, self.codec))
|
2010-04-24 13:31:11 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
def begin_page(self, page, ctm):
|
Many changes to make pdf2txt.py work better in Py3, some in that script, others in module!
Sorry, changes should have been more atomic.
*In pdf2txt.py:*
* Re-wrote main function to use argparse instead of optparse.
* Manually tested in Py2/Py3 to get partial consistency.
* Errors abound including Tags mode, but most modes weren't working at all in Py3 anyway.
* Py2 mode *probably* unchanged, cannot find any bugs yet...
* Kept old main function for posterity, for now.
*In utils:*
* Added a few compatibility functions (some string hax required chardet, new dependency):
- make_compat_bytes(in_str)-> (py3->bytes | py2->str)
- make_compat_str(in_str)-> (str)
- compatible_encode_method(bytesorstring, encoding, erraction)-> (str)
*In pdfdevice:*
* To handle different output filetypes in Py3, injected lots of calls to new utils methods,
as well as some six.PYX checks and logic. These changes are largely responsible for
enhanced Py2/Py3 consistency.
*In converter:*
* To handle output filetypes in Py2, injected a few checks and fixes particularly around the
py2 `str.encode` method and its *assumed* usual use-analogies in Py3.
2015-05-17 20:08:57 +00:00
|
|
|
output = '<page id="%s" bbox="%s" rotate="%d">' % (self.pageno, utils.bbox2str(page.mediabox), page.rotate)
|
|
|
|
self.outfp.write(utils.make_compat_bytes(output))
|
2010-04-24 13:31:11 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
def end_page(self, page):
|
Many changes to make pdf2txt.py work better in Py3, some in that script, others in module!
Sorry, changes should have been more atomic.
*In pdf2txt.py:*
* Re-wrote main function to use argparse instead of optparse.
* Manually tested in Py2/Py3 to get partial consistency.
* Errors abound including Tags mode, but most modes weren't working at all in Py3 anyway.
* Py2 mode *probably* unchanged, cannot find any bugs yet...
* Kept old main function for posterity, for now.
*In utils:*
* Added a few compatibility functions (some string hax required chardet, new dependency):
- make_compat_bytes(in_str)-> (py3->bytes | py2->str)
- make_compat_str(in_str)-> (str)
- compatible_encode_method(bytesorstring, encoding, erraction)-> (str)
*In pdfdevice:*
* To handle different output filetypes in Py3, injected lots of calls to new utils methods,
as well as some six.PYX checks and logic. These changes are largely responsible for
enhanced Py2/Py3 consistency.
*In converter:*
* To handle output filetypes in Py2, injected a few checks and fixes particularly around the
py2 `str.encode` method and its *assumed* usual use-analogies in Py3.
2015-05-17 20:08:57 +00:00
|
|
|
self.outfp.write(utils.make_compat_bytes('</page>\n'))
|
2010-04-24 13:31:11 +00:00
|
|
|
self.pageno += 1
|
|
|
|
return
|
|
|
|
|
|
|
|
def begin_tag(self, tag, props=None):
|
|
|
|
s = ''
|
2010-08-26 15:02:46 +00:00
|
|
|
if isinstance(props, dict):
|
Many changes to make pdf2txt.py work better in Py3, some in that script, others in module!
Sorry, changes should have been more atomic.
*In pdf2txt.py:*
* Re-wrote main function to use argparse instead of optparse.
* Manually tested in Py2/Py3 to get partial consistency.
* Errors abound including Tags mode, but most modes weren't working at all in Py3 anyway.
* Py2 mode *probably* unchanged, cannot find any bugs yet...
* Kept old main function for posterity, for now.
*In utils:*
* Added a few compatibility functions (some string hax required chardet, new dependency):
- make_compat_bytes(in_str)-> (py3->bytes | py2->str)
- make_compat_str(in_str)-> (str)
- compatible_encode_method(bytesorstring, encoding, erraction)-> (str)
*In pdfdevice:*
* To handle different output filetypes in Py3, injected lots of calls to new utils methods,
as well as some six.PYX checks and logic. These changes are largely responsible for
enhanced Py2/Py3 consistency.
*In converter:*
* To handle output filetypes in Py2, injected a few checks and fixes particularly around the
py2 `str.encode` method and its *assumed* usual use-analogies in Py3.
2015-05-17 20:08:57 +00:00
|
|
|
s = ''.join(' %s="%s"' % (utils.enc(k), utils.enc(str(v))) for (k, v)
|
2013-11-07 08:35:04 +00:00
|
|
|
in sorted(props.iteritems()))
|
Many changes to make pdf2txt.py work better in Py3, some in that script, others in module!
Sorry, changes should have been more atomic.
*In pdf2txt.py:*
* Re-wrote main function to use argparse instead of optparse.
* Manually tested in Py2/Py3 to get partial consistency.
* Errors abound including Tags mode, but most modes weren't working at all in Py3 anyway.
* Py2 mode *probably* unchanged, cannot find any bugs yet...
* Kept old main function for posterity, for now.
*In utils:*
* Added a few compatibility functions (some string hax required chardet, new dependency):
- make_compat_bytes(in_str)-> (py3->bytes | py2->str)
- make_compat_str(in_str)-> (str)
- compatible_encode_method(bytesorstring, encoding, erraction)-> (str)
*In pdfdevice:*
* To handle different output filetypes in Py3, injected lots of calls to new utils methods,
as well as some six.PYX checks and logic. These changes are largely responsible for
enhanced Py2/Py3 consistency.
*In converter:*
* To handle output filetypes in Py2, injected a few checks and fixes particularly around the
py2 `str.encode` method and its *assumed* usual use-analogies in Py3.
2015-05-17 20:08:57 +00:00
|
|
|
out_s = '<%s%s>' % (utils.enc(tag.name), s)
|
|
|
|
self.outfp.write(utils.make_compat_bytes(out_s))
|
2011-02-14 13:51:20 +00:00
|
|
|
self._stack.append(tag)
|
2010-04-24 13:31:11 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
def end_tag(self):
|
2017-05-29 07:06:09 +00:00
|
|
|
assert self._stack, str(self.pageno)
|
2011-02-14 13:51:20 +00:00
|
|
|
tag = self._stack.pop(-1)
|
Many changes to make pdf2txt.py work better in Py3, some in that script, others in module!
Sorry, changes should have been more atomic.
*In pdf2txt.py:*
* Re-wrote main function to use argparse instead of optparse.
* Manually tested in Py2/Py3 to get partial consistency.
* Errors abound including Tags mode, but most modes weren't working at all in Py3 anyway.
* Py2 mode *probably* unchanged, cannot find any bugs yet...
* Kept old main function for posterity, for now.
*In utils:*
* Added a few compatibility functions (some string hax required chardet, new dependency):
- make_compat_bytes(in_str)-> (py3->bytes | py2->str)
- make_compat_str(in_str)-> (str)
- compatible_encode_method(bytesorstring, encoding, erraction)-> (str)
*In pdfdevice:*
* To handle different output filetypes in Py3, injected lots of calls to new utils methods,
as well as some six.PYX checks and logic. These changes are largely responsible for
enhanced Py2/Py3 consistency.
*In converter:*
* To handle output filetypes in Py2, injected a few checks and fixes particularly around the
py2 `str.encode` method and its *assumed* usual use-analogies in Py3.
2015-05-17 20:08:57 +00:00
|
|
|
out_s = '</%s>' % utils.enc(tag.name)
|
|
|
|
self.outfp.write(utils.make_compat_bytes(out_s))
|
2010-04-24 13:31:11 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
def do_tag(self, tag, props=None):
|
|
|
|
self.begin_tag(tag, props)
|
2011-02-14 13:51:20 +00:00
|
|
|
self._stack.pop(-1)
|
2010-04-24 13:31:11 +00:00
|
|
|
return
|