Comments (3)
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.
@AlexandreGalois is it ok ? Please reopen if not.
from pdfminer.six.
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)
- Can not extract image from pdf HOT 3
- Cannot install from source with latest pip/setuptools, incompatible with Python 3.12
- original_path extraction error regarding LTCurve HOT 2
- Import error HOT 1
- Bug: pdfminer.six fails to read certain japanese fonts and returns cid value HOT 3
- Check licenses in cicd
- Switch to pyproject.toml
- I want to take bold text from a .pdf file and i have a code that works perfectly wow but in one kind of pdf it did't work can anyone help me with that HOT 1
- Incorrect character extraction, CID string returned HOT 2
- TypeError: 'int' object is not iterable HOT 1
- Support zipped jpegs
- Detection of ligatures - fi problem
- Unused `rsrcmgr` field on `PDFDevice`
- interpreter.process_page crashes on certain pdfs
- 𝜒 extraction issue
- "PDFDocument is not initialized" when startxref is invalid
- Out-of-order coordinates HOT 4
- pdfminer cause python3 process coredump.... HOT 1
- UnicodeEncodeError when piping/Tee-Object on Windows
- Parse Image on the fly
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pdfminer.six.