Tabula Py Readthedocs Io en Latest
Tabula Py Readthedocs Io en Latest
Tabula Py Readthedocs Io en Latest
1 Getting Started 3
1.1 Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.2 Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.3 Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2 FAQ 5
2.1 tabula-py does not work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.2 I can’t run from tabula import read_pdf . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.3 I got a empty DataFrame. How can I resolve it? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.4 The result is different from tabula-java. Or, stream option seems not to work appropriately . . 6
2.5 Can I use option xxx? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.6 How can I ignore useless area? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.7 I faced ParserError: Error tokenizing data. C error. How can I extract multiple
tables? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.8 I want to prevent tabula-py from stealing focus on every call on my mac . . . . . . . . . . . . . . . . 8
2.9 I got ? character with result on Windows. How can I avoid it? . . . . . . . . . . . . . . . . . . . . . 8
2.10 I can’t extract file/directory name with space on Windows . . . . . . . . . . . . . . . . . . . . . . . 8
2.11 I want to use a different tabula .jar file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.12 I want to extract multiple tables from a document . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.13 Table cell contents sometimes overflow into the next row. . . . . . . . . . . . . . . . . . . . . . . . 9
2.14 I got a warning/error message from PDFBox including org.apache.pdfbox.pdmodel.. Is it
the cause of empty dataframe? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.15 I can’t figure out accurate extraction with tabula-py. Are there any similar Python libraries? . . . . . 9
3 Contributing to tabula-py 11
3.1 Code formatting and testing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
3.2 Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
4 tabula 13
4.1 High level interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
4.2 Internal interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
5 tabula.errors 23
i
Index 29
ii
tabula-py
tabula-py is a simple Python wrapper of tabula-java, which can read table of PDF. You can read tables from PDF
and convert into pandas’s DataFrame. tabula-py also enables you to convert a PDF file into CSV/TSV/JSON file.
We highly recommend to look at the example notebook and try it on Google Colab.
For high level API reference, see High level interfaces.
Contents 1
tabula-py
2 Contents
CHAPTER 1
Getting Started
1.1 Requirements
• Java
– Java 8+
• Python
– 3.5+
1.2 Installation
Before installing tabula-py, ensure you have Java runtime on your environment.
You can install tabula-py form PyPI with pip command.
Note: conda recipe on conda-forge is not maintained by us. We recommend to install via pip to use latest version of
tabula-py.
3
tabula-py
• If there’s a FileNotFoundError when it calls read_pdf(), and when you type java on command line
it says 'java' is not recognized as an internal or external command, operable
program or batch file, you should set PATH environment variable to point to the Java directory.
• Find the main Java folder like jre... or jdk.... On Windows 10 it was under C:\Program
Files\Java
• On Windows 10: Control Panel -> System and Security -> System -> Advanced System Settings -> Envi-
ronment Variables -> Select PATH –> Edit
• Add the bin folder like C:\Program Files\Java\jre1.8.0_144\bin, hit OK a bunch of times.
• On command line, java should now print a list of options, and tabula.read_pdf() should run.
1.3 Example
tabula-py enables you to extract tables from a PDF into a DataFrame, or a JSON. It can also extract tables from a PDF
and save the file as a CSV, a TSV, or a JSON.
import tabula
See example notebook for more detail. I also recommend to read the tutorial article written by @aegis4048.
Note: If you face some issue, we’d recommend to try tabula.app to see the limitation of tabula-java. Also, see FAQ
as well.
FAQ
There are several possible reasons, but tabula-py is just a wrapper of tabula-java , make sure you’ve installed Java
and you can use java command on your terminal. Many issue reporters forget to set PATH for java command.
You can check whether tabula-py can call java from Python process with tabula.environment_info() func-
tion.
If you’ve installed tabula, it will be conflict the namespace. You should install tabula-py after removing
tabula.
Before tuning the tabula-py option, you have to check you set an appropreate pages option. By default, tabula-py
extracts table from first page of your PDF, with pages=1 argument. If you want to extract from all pages, you need to
set pages option like pages=”all” or pages=[1, 2, 3]. You might want to extract multiple tables from multiple pages,
if so you need to set multiple_tables=True together.
Depending on the PDF’s complexity, it might be difficult to extract table contents accuracy.
Tuning points of tabula-py are limited:
• Set specific area for accurate table detection
• Try lattice=True option for the table having explicit line. Or try stream=True option
5
tabula-py
To know the limitation of tabula-java, I highly recommend to use tabula app, the GUI version of tabula-java.
tabula app can:
• specify the area with GUI
• show preview of the extraction with lattich or stream mode
• export template that is reusable for tabula-py
Even if you can’t extract tabula-py for those table contents which can be extracted tabula app appropriately, file an
issue on GitHub.
tabula-py set guess option True by default, for beginners. It is known to make a conflict between stream
option. If you feel something strange with your result, please set guess=False.
Yes. You can use options argument as following. The format is same as cli of tabula-java.
According to tabula-java wiki, there is a explain how to specify the area: https://github.com/tabulapdf/tabula-java/
wiki/Using-the-command-line-tabula-extractor-tool#grab-coordinates-of-the-table-you-want
For example, using macOS’s preview, I got area information of this PDF:
6 Chapter 2. FAQ
tabula-py
given
# Note the left, top, height, and width parameters and calculate the following:
y1 = top
x1 = left
(continues on next page)
This error occurs pandas trys to extract multiple tables with different column size at once. Use multiple_tables
option, then you can avoid this error.
2.9 I got ? character with result on Windows. How can I avoid it?
If the encoding of PDF is UTF-8, you should set chcp 65001 on your terminal before launching a Python process.
chcp 65001
Then you can extract UTF-8 PDF with java_options="-Dfile.encoding=UTF8" option. This option will
be added with encoding='utf-8' option, which is also set by default.
Replace 65001 and UTF-8 appropriately, if the file encoding isn’t UTF-8.
export TABULA_JAR=".../tabula-x.y.z-jar-with-dependencies.jar"
8 Chapter 2. FAQ
tabula-py
df = read_pdf(file_path, multiple_tables=True)
The result will be a list of DataFrames. If you want separate tables across all pages in a document, use the pages
argument.
2.13 Table cell contents sometimes overflow into the next row.
You can try using lattice=True, which will often work if there are lines separating cells in the table.
2.15 I can’t figure out accurate extraction with tabula-py. Are there
any similar Python libraries?
I know tabula-py has limitation depending on tabula-java. Sometimes your PDF is too complex to tabula-py. If you
want to find plan B, there are similar packages as the following:
• https://github.com/jsvine/pdfplumber
• https://camelot-py.readthedocs.io/en/master/
10 Chapter 2. FAQ
CHAPTER 3
Contributing to tabula-py
If you want to become a contributor, you can install dependency after cloning the repo as follows:
nox .
3.2 Documentation
The documentation source is under docs/ directory and the document is published on Read the Docs automatically.
11
tabula-py
tabula
4.1.1 tabula.io
This module is a wrapper of tabula, which enables table extraction from a PDF.
This module extracts tables from a PDF into a pandas DataFrame. Currently, the implementation of this module uses
subprocess.
Instead of importing this module, you can import public interfaces such as read_pdf(),
read_pdf_with_template(), convert_into(), convert_into_by_batch() from tabula mod-
ule directory.
Note: If you want to use your own tabula-java JAR file, set TABULA_JAR to environment variable for JAR path.
Example
13
tabula-py
Examples
Note: As of tabula-java 1.0.3, guess option becomes independent from lattice and stream
option, you can use guess and lattice/stream option at the same time.
Note: If you want to use multiple area options and extract in one table, it should be better
to set multiple_tables=False for read_pdf()
Examples
Example
14 Chapter 4. tabula
tabula-py
Example
"-Xmx256m".
• kwargs – Dictionary of option for tabula-java. Details are shown in build_options()
Raises
• FileNotFoundError – If downloaded remote file doesn’t exist.
• ValueError – If output_format is unknown format, or if downloaded remote file size is
0.
• tabula.errors.JavaNotFoundError – If java is not installed or found.
• subprocess.CalledProcessError – If tabula-java execution failed.
tabula.io.convert_into_by_batch(input_dir, output_format=’csv’, java_options=None,
**kwargs)
Convert tables from PDFs in a directory.
Parameters
• input_dir (str) – Directory path.
• output_format (str, optional) – Output format of this function (csv, json or tsv)
• java_options (list, optional) – Set java options like -Xmx256m.
• kwargs – Dictionary of option for tabula-java. Details are shown in build_options()
Returns Nothing. Outputs are saved into the same directory with input_dir
Raises
• ValueError – If input_dir doesn’t exist.
• tabula.errors.JavaNotFoundError – If java is not installed or found.
• subprocess.CalledProcessError – If tabula-java execution failed.
tabula.io.read_pdf(input_path, output_format=None, encoding=’utf-8’, java_options=None, pan-
das_options=None, multiple_tables=True, user_agent=None, **kwargs)
Read tables in PDF.
Parameters
• input_path (str, path object or file-like object) – File like object of
tareget PDF file. It can be URL, which is downloaded by tabula-py automatically.
• output_format (str, optional) – Output format for returned object (dataframe
or json)
Example
["-Xmx256m"]
• pandas_options (dict, optional) – Set pandas options.
Example
{'header': None}
• user_agent (str, optional) – Set a custom user-agent when download a pdf from
a url. Otherwise it uses the default urllib.request user-agent.
• kwargs – Dictionary of option for tabula-java. Details are shown in build_options()
Returns list of DataFrames or dict.
Raises
• FileNotFoundError – If downloaded remote file doesn’t exist.
• ValueError – If output_format is unknown format, or if downloaded remote file size is
0.
• tabula.errors.CSVParseError – If pandas CSV parsing failed.
• tabula.errors.JavaNotFoundError – If java is not installed or found.
• subprocess.CalledProcessError – If tabula-java execution failed.
Examples
Here is a simple example. Note that read_pdf() only extract page 1 by default.
Notes: As of tabula-py 2.0.0, read_pdf() sets multiple_tables=True by default. If you want to get consistent
output with previous version, set multiple_tables=False.
16 Chapter 4. tabula
tabula-py
18 Chapter 4. tabula
tabula-py
Examples
20 Chapter 4. tabula
tabula-py
4.1.2 tabula.util
4.2.1 tabula.template
tabula.template.load_template(path_or_buffer)
Build tabula-py option from template file
Parameters path_or_buffer (str, path object or file-like object) – File
like object of Tabula app template.
Returns tabula-py options
Return type dict
4.2.2 tabula.file_util
tabula.file_util.is_file_like(obj)
Check file like object
Parameters obj – file like object.
Returns file like object or not
Return type bool
22 Chapter 4. tabula
CHAPTER 5
tabula.errors
23
tabula-py
24 Chapter 5. tabula.errors
CHAPTER 6
• genindex
• modindex
• search
25
tabula-py
t
tabula.errors, 23
tabula.file_util, 21
tabula.io, 13
tabula.template, 21
tabula.util, 21
27
tabula-py
B
build_options() (in module tabula.io), 13
C
convert_into() (in module tabula.io), 14
convert_into_by_batch() (in module tabula.io),
15
CSVParseError, 23
E
environment_info() (in module tabula.util), 21
I
is_file_like() (in module tabula.file_util), 21
J
java_version() (in module tabula.util), 21
JavaNotFoundError, 23
L
load_template() (in module tabula.template), 21
localize_file() (in module tabula.file_util), 21
R
read_pdf() (in module tabula.io), 15
read_pdf_with_template() (in module tab-
ula.io), 19
T
tabula.errors (module), 23
tabula.file_util (module), 21
tabula.io (module), 13
tabula.template (module), 21
tabula.util (module), 21
29