Giter Club home page Giter Club logo

Comments (3)

vstoykov avatar vstoykov commented on May 19, 2024

Hello @AlexandreGalois, may I suggest you to edit your issue description in order code to be more readable. You can use

```
Some code here
```

Then in order to fix your code you can try to import StringIO from io module.

from io import StringIO

do not use cStringIO or StringIO modules, they are for Python 2.5 compatibility. From Python 2.6 and up io module is preferable (because this is the only module in Python3).

from pdfminer.six.

goulu avatar goulu commented on May 19, 2024

@AlexandreGalois is it ok ? Please reopen if not.

from pdfminer.six.

michi88 avatar michi88 commented on May 19, 2024

Ran into this issue as well.

When passing io.StringIO in python 2, self.outfp_binary is False but text in def write_text is six.binary_type and thus fails.

class TextConverter(PDFConverter):

    def __init__(self, rsrcmgr, outfp, codec='utf-8', pageno=1, laparams=None,
                 showpageno=False, imagewriter=None):
        PDFConverter.__init__(self, rsrcmgr, outfp, codec=codec, pageno=pageno, laparams=laparams)
        self.showpageno = showpageno
        self.imagewriter = imagewriter
        return

    def write_text(self, text):
        text = utils.compatible_encode_method(text, self.codec, 'ignore')
        if six.PY3 and self.outfp_binary:
            text = text.encode()
        self.outfp.write(text)
        return

...

It only works with BytesIO.

text should probably be decoded when output is not self.outfp_binary.

Hack to get it working is:

def extract_text_from_pdf(pdf_file):
    out = io.BytesIO()
    pdfminer.high_level.extract_text_to_fp(pdf_file, out, codec='utf-8')
    out.seek(0)
    return out.read().decode('utf-8')

from pdfminer.six.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.