Extract CSV data tables from PDF files. It's a node wrapper for the mighty tabula-java 0.9.0.
npm install tabula-jsHelps you extract CSV data tables from PDF files. It's a node wrapper for the mighty tabula-java 0.9.0.
Not all tabula-java options are exposed. Particularly wirting to file but any extracted data is available through a callback or a stream.
Here are the options:
``
Options:
area Portion of the page to analyze (top,left,bottom,right).
Example: "269.875,12.75,790.5,561". Default is entire page.
columns
"10.1,20.2,30.3"
debug Print detected table areas instead ofprocessing.
guess Guess the portion of the page to analyze per page.
silent Suppress all stderr output.
noSpreadsheet Force PDF not to be extracted using spreadsheet-style
extraction
(if there are ruling lines separating each cell, as in a PDF of an Excel spreadsheet)
pages
Examples: pages: "1-3,5-7", pages: "3" or pages: "all". Default is pages: "1"
spreadsheet Force PDF to be extracted using spreadsheet-style
extraction
(if there are ruling lines separating each cell, as in a PDF of an Excel spreadsheet)
password
useLineReturns Use embedded line returns in cells. (Only in spreadsheet
mode.)
`
This is the simplest use case. It's uses a classic node style callback `(err, data)`. The extracted CSV is an array of all rows found in the data table including any headers.
` js`
const tabula = require('tabula-js');
const t = tabula(source.pdf);
t.extractCsv((err, data) => console.log(data));
Here we use the `area` option to zero in on the data.
` js`
const tabula = require('tabula-js');
const t = tabula(source.pdf, {area: "269.875,150,690,545"});
t.extractCsv((err, data) => console.log(data));
Is similar to the callback version but with data extracted as a stream.
` js`
const tabula = require('tabula-js');
const stream = tabula(source.pdf).streamCsv();
stream.pipe(process.stdout);
In reality the library is built on the notion of streams all the way down. Highland.js is used to make this a breeze.
This also means the returned stream can readily perform highland.js style transformations and operations.
` js``
const tabula = require('tabula-js');
const stream = tabula(source.pdf).streamCsv();
stream
.split()
.doto(console.log)
.done(() => console.log('ALL DONE!'));
This library would not be possible without the amazing effort of the tabula-java team. Thank you!