pdf-to-xlsx
PDF to Excel
Pull the tables out of a PDF into a workbook, one sheet per table.
- Reads
- a PDF — application/pdf
- Writes
- one file — workbooks
- Tool page
- /pdf-to-excel
Example
Turn the tables in a report into a workbook, one sheet per page.
Given
- accounts.pdf — a PDF holding a ruled table
From code
import { loadDocument, runOperation } from '@pagecraft/core';
const accounts = await loadDocument({ bytes, name: 'accounts.pdf' });
const [output] = await runOperation('pdf-to-xlsx', [accounts], {
numbers: true,
});
From a shell
pagecraft pdf-to-xlsx accounts.pdf
What comes back
One workbook.
This example is run by the test suite. If it stopped being true, the build would fail.
Options
pages--pages
string, a page selection: '1-3, 7, 9-', 'even', 'last'
Pages
Which pages to take the tables from.
Default: 'all'
numbers--numbers
boolean
Read figures as numbers
Put a cell that plainly holds a figure in as a number rather than as text.
Default: true
What it cannot do
- A PDF does not record what was a table; it records text in places. A table is found by the lines drawn around it, or by its columns lining up, and a table that has neither is read as ordinary text.
- A merged cell is only visible where the file drew the lines: a table nobody ruled reports no merges, because a wide cell and an empty one beside it look exactly alike from the text.
- Only cells that are plainly figures become numbers. A code that happens to be digits stays text, because a spreadsheet that makes 007 into 7 has lost something nobody can get back.
- Nothing but the cells comes across: not the fonts, not the colours, not the widths the table was set to, and no formula, because a PDF holds none.
- One table becomes one sheet. A table split across two pages becomes two sheets, because nothing in the file says the second is a continuation of the first.
- A scanned page holds a picture of a table. Run OCR over it first.