Schema CPA

Invoice Line Item Extraction for Multi-Page Invoices

By Schema CPAPublished Updated

Invoice line item extraction turns each row of an invoice's item table into its own spreadsheet row: description, quantity, unit price and line amount. It means finding the table, joining it across pages, dropping repeated headers and page subtotals, and then proving the extracted lines, plus discount, freight and tax, add up to the printed invoice total.

Why are invoice line items harder to extract than header fields?

Invoice line items are harder to extract than header fields because a header field is one value with a label, while an item table is a grid whose shape changes from vendor to vendor. Column order, wrapped descriptions, missing borders and blank cells all change how the rows have to be read.

Header fields, such as the vendor name, invoice number and date, appear once and are usually labelled. Which of those come off reliably is covered in which invoice header fields can be extracted reliably. Line items have no label per value. Software has to work out that a number belongs to the "Qty" column because of where it sits, not because of what it says.

The common ways item tables vary:

  • Column order. One vendor prints Description, Qty, Price, Amount. Another prints Item code, Qty, Description, Amount, Price. A reader that assumes an order will put the price in the quantity column.
  • Wrapped descriptions. A long product name wraps onto a second line. Read naively, the second line becomes a row of its own with a description and no amounts.
  • Missing borders. Many invoices draw no lines between columns. The columns exist only as white space, and a long description can push into the space where the next column starts.
  • Blank cells. A service line may have an amount but no quantity or unit price. A row with a blank cell can shift the remaining values one column to the left.
  • Extra columns. Item codes, units of measure, tax flags and per-line discounts appear on some invoices and not others.

The difficulty is documented in the tools themselves. The Tesseract OCR project's page on improving the quality of the output states that Tesseract has a known problem recognising data in tables without custom layout analysis. Microsoft's documentation for the Power Query PDF connector has a section on rows that span several lines and are not identified correctly, and suggests cleaning them up afterwards by filling down or grouping adjacent rows.

Invoice line item tables that continue across pages

Invoice line item tables that continue across pages have to be joined into one table before any total is checked. Joining means keeping the item rows from every page in order, dropping the column headers repeated at the top of each page, and removing "carried forward" or page subtotal lines so they are not counted as items.

A multi-page invoice usually repeats the table heading on each page so a reader can follow it. Some vendors also print a page subtotal at the bottom of each page and a "brought forward" line at the top of the next. Those lines are useful on paper and harmful in a spreadsheet: count them as items and the lines add up to far more than the invoice total.

Steps for joining a split table:

  1. Confirm every page is present. A page count printed on the invoice, such as "Page 2 of 3", tells you whether a page is missing. Line numbers that jump from 18 to 31 tell you the same thing.
  2. Keep one header. Take the column headings from the first page and delete the repeated heading rows on later pages.
  3. Remove page totals and carry lines. Look for rows labelled "Subtotal this page", "Carried forward", "Brought forward" or "Continued". Delete them from the item rows, but note their amounts. A page subtotal is a free check on the rows above it.
  4. Check that the columns line up. A later page can have slightly different column widths, which moves values into the wrong column. Spot-check the first row of each page.
  5. Keep the summary block separate. The subtotal, discount, freight, tax and total at the end of the last page are header values, not item rows.

Excel can do part of this when the PDF contains text. The Power Query PDF connector has a MultiPageTables option, on by default, that combines similar tables on consecutive pages into a single table, and StartPage and EndPage options to limit which pages are read. Microsoft's page on the Power Query PDF connector describes these settings. The combined table still contains any repeated headers and page subtotals the vendor printed, so steps 2 and 3 remain.

Does the invoice total match its line items?

An invoice total matches its line items when each line's quantity times unit price equals its line amount, the line amounts sum to the printed subtotal, and the subtotal minus discounts plus freight plus tax equals the printed total. Any break in that chain means a line was misread, missed or counted twice.

This check matters more than any other step in line item extraction. A misread digit in one line amount almost never leaves the sum unchanged, so a total that ties is strong evidence the lines are right. A total that does not tie tells you exactly how far off you are, and the size of the difference often points to the line.

A worked three-line invoice

This example is a fictional invoice from Lakeside Paper Supply Co. to an example client, invoice number INV-004821. All amounts and the tax rate are made up for illustration.

LineDescriptionQtyUnit priceLine amountCheck
1Copy paper, case406.25250.0040 × 6.25 = 250.00
2Toner cartridge1248.50582.0012 × 48.50 = 582.00
3Desk organiser322.0066.003 × 22.00 = 66.00
Merchandise subtotal898.00250.00 + 582.00 + 66.00
Discount, 5% of merchandise−44.90898.00 × 0.05
Freight35.00As printed
Sales tax, example rate 8% on 853.1068.25853.10 × 0.08 = 68.248, rounded
Invoice total956.35898.00 − 44.90 + 35.00 + 68.25

The printed total on this example invoice is 956.35, so the lines tie. In this example the invoice itself states that tax was charged on the discounted merchandise of 853.10 and not on freight. Take the tax base from the invoice rather than assuming one, because what is taxable depends on the jurisdiction and the vendor.

Now suppose line 2 had been read as 12 × 48.50 = 682.00, a 5 misread as a 6. The lines would sum to 998.00, the chain would end at a total well above 956.35, and the difference would be exactly 100.00 before discount and tax. A round difference like that usually means one misread digit.

Rounding

Line amounts are often rounded to the cent after multiplying, and tax is rounded once on the total or once per line depending on the vendor. Expect differences of a cent or two on invoices with many lines. Decide in advance how large a difference is accepted as rounding, and send anything larger to a person.

Discount, freight and tax lines inside the item table

Discount, freight and tax lines inside the item table are rows that look like items but are not goods. Some vendors put them in the summary block. Others list them as rows among the products, with their own description and amount. Either way they change the total, so they must be captured and labelled differently from product lines.

Ways these lines appear:

  • Discount as a row. A line reading "Early payment discount" or "Promo 10OFF" with a negative amount. Treat it as a reduction, not as a product with a negative price.
  • Per-line discounts. A discount column that reduces each line, so the line amount is less than quantity times price. The arithmetic check per line has to include it.
  • Freight, delivery and handling. A row such as "Shipping" or "Fuel surcharge" with an amount and no quantity.
  • Tax as a row. A "Sales tax" row inside the table rather than below it, sometimes with a different rate per line or a tax flag column showing which lines were taxed.
  • Deposits and credits. A prior deposit or a credit memo applied to this invoice, shown as a negative row.

Label each extracted row with a type: item, discount, freight, tax or credit. The total check then becomes: items, minus discounts and credits, plus freight, plus tax, equals the printed total. Without the label, a freight row can be coded to the wrong expense, and a tax row can be added twice if the summary block also shows it.

Once rows are labelled, item lines can be assigned to the client's expense categories. How to set those categories up is the subject of building an expense category list for bookkeeping clients.

When a single invoice total line beats full line item detail

A single invoice total line beats full line item detail when every line on the invoice would be coded to the same account. A monthly software subscription, a utility bill or a rent invoice gains nothing from separate rows. Capturing the header and total, with the vendor and date, gives the books what they need.

Line items earn their effort in narrower cases:

  • Mixed purchases. One invoice covers office supplies, equipment and resale stock that belong in different accounts.
  • Partly taxable invoices. Some lines are taxed and others are not, and the split matters to the client's records.
  • Job or project costing. Lines need to be charged to different jobs, locations or departments.
  • Inventory. Quantities and unit costs feed an inventory count or cost.
  • Disputes and credits. A client is disputing one line or expecting a credit for returned items.

For everything else, extract the header, check that subtotal, tax and freight add up to the total, and keep the invoice image on file so the lines can be read later if a question comes up. The IRS's Publication 583 lists invoices among the supporting documents a business keeps, so the document stays available even when only its total is entered.

How firms usually get this wrong

The most common mistake is capturing line items for every invoice because the tool can, then never using them. Thousands of rows from utility bills make the spreadsheet harder to review without changing a single posting.

The second mistake is the opposite: capturing only totals for a client whose invoices mix capital purchases with supplies, then having to reopen every invoice at year end.

The third is skipping the total check because the lines "looked right". A wrapped description that became its own row, or a page subtotal counted as an item, is invisible until the lines are summed.

Schema CPA reads vendor invoices that clients send through their upload link and flags a copy that arrives a second time instead of counting it again. The workflow section of the homepage shows where that duplicate check sits before the Excel or CSV export.

For how the text gets off the page in the first place, see invoice OCR, and for what to look for when buying a tool that does it, see how to choose invoice OCR software. Ledgers and trial balances built from these rows are covered in the financial statements and ledgers category.

All posts in Receipts and invoices