1. Why copy-paste and naive OCR corrupt trade PDFs
PDF is a page-layout coordinate format rather than a tabular data format. A wholesale line sheet or multi-page trade invoice stores glyph runs at (x, y) coordinates with no native row or column elements. When a supplier exports a catalogue with merged category banners, two-line descriptions, pack-of-six pricing and repeated page headers, standard text selection scrambles column alignment.
Feeding raw text into an unconstrained language model introduces a worse failure mode: silent digit substitution or rounded totals that look plausible at a glance. A reliable B2B conversion pipeline separates layout reconstruction from deterministic schema and arithmetic verification so every extracted cell either reconciles to the penny or is explicitly flagged for human review.
- Page-break continuation stitching: Repeated running headers, footer page numbers and subtotal carry-forwards are stripped before table rows are merged into one logical dataset.
- Pack-quantity disambiguation: Columns such as
MOQ,Case Qty(VE 6,Colis de 12) and unit trade cost are separated so a case price is not accidentally imported as a single-unit retail price. - Barcode string preservation: 8-, 12-, 13- and 14-digit GTIN/EAN/UPC strings are typed as strings from the start so spreadsheet tools never strip leading zeros or format barcodes in scientific notation.
2. Multilingual column header normalisation
European and UK trade suppliers rarely use English-only column labels that match Shopify or Xero import templates verbatim. A deterministic synonym dictionary paired with column-value pattern checks maps supplier headers into canonical fields (sku, title, ean, packQty, unitCostMinor, rrpMinor, taxRateBps, lineTotalMinor) before target templates are emitted.
Locale number parsing runs alongside header detection. Continental European price lists routinely use a period or narrow space as the thousands separator and a comma as the decimal separator (1.249,50 €), whereas UK and US documents invert that convention (£1,249.50). Detecting the document locale first prevents thousand-fold price errors.
// Canonical extracted row (integer minor units, never floats)
{
"sku": "VLV-22-BR",
"ean": "05060012345678",
"description": "22mm Brass Isolation Valve (Pack of 10)",
"quantity": 4,
"unitAmountMinor": 1850, // £18.50
"taxAmountMinor": 1480, // £14.80 (20% UK VAT on £74.00 net)
"grossTotalMinor": 8880 // £88.80 -> 4 * 1850 + 1480 === 8880 (PASS)
}
// Emitted Xero purchase bill row:
// *ContactName,*InvoiceNumber,*InvoiceDate,*DueDate,ItemCode,Description,*Quantity,*UnitAmount,*AccountCode,*TaxType
// " Northgate Brass Ltd","INV-88412","2026-11-18","2026-12-18","VLV-22-BR","22mm Brass Isolation Valve (Pack of 10)",4,18.50,"310","20% (VAT on Expenses)"3. Penny-exact validation in integer minor units
Binary floating-point arithmetic cannot represent base-10 decimals such as 0.10 or 19.99 exactly (41.25 * 12 or multi-rate tax splits routinely accumulate sub-penny drift). In @repo/pipeline-kit and our pdf.convert engine operation, decimal strings are parsed straight into integer minor units (Money.amountMinor) via regex digit extraction (moneyFromMajor), never parseFloat.
Once every row is represented as integers, two classes of deterministic invariants run across the whole file before any CSV is written:
- Payables & invoice line reconciliation: Checks
quantity × unitNetMinor - discountMinor === lineNetMinorand sums line totals against the printed invoice subtotal, tax summary by rate band and grand total. - Catalogue margin & RRP sanity check: When a price list carries both trade buy price and recommended retail price (
RRP/UVP), flags any SKU whererrpMinor < unitCostMinoror where a variant SKU appears twice with conflicting prices. - Non-destructive exception flagging: When a supplier's own printed PDF contains a rounding discrepancy, the converter never invents a silent correction; it marks the row in
validation.issues[]and isolates it on a dedicated review tab in the XLSX workbook.
4. Pre-import checklist for Shopify, WooCommerce and Xero
Storefront and accounting importers apply strict validation rules on upload. Shopify groups multi-size or multi-colour products by shared Handle, requiring Title and Vendor on the first row of each handle group while variant rows carry Option1 Value, Variant SKU and Variant Price. WooCommerce separates Type (simple, variable, variation) and Parent SKU references. Xero requires exact matches between TaxType strings and the tax rates configured in your chart of accounts.
You can inspect how our parser handles pages 1–2 of your own PDF at /tools/pdf-to-erp (pdf.preview, 0 API units) before unlocking full conversion files or automating recurring supplier drops through POST /api/v1/engines/pdf/convert.