
Extract the text of a PDF into clean, structured XML — one element per line or per paragraph — for databases, pipelines and archives. Your file never leaves your browser.
By Amir Shahzad · Last updated 21 November 2026 · Data: pdf.js 3.11.174, pdf-lib 1.17; XML 1.0, Fifth Edition (W3C, 2008)
No PDF chosen yet. Pick a PDF above — or try the built-in sample first.
Short answer: choose your PDF, pick line or paragraph mode, press Convert to XML — the text is extracted in your browser and structured into well-formed XML, checked with a strict parser, then previewed for you to copy or download. Nothing is uploaded.
A PDF is a picture of a document: it knows where every letter sits on the page, but it does not know what a heading, a paragraph or a table row is. XML is the opposite — a strict, self-describing tree that databases, APIs and data pipelines can parse without guessing. This tool bridges the two: it reads the PDF's text layer with the open-source pdf.js extractor, groups the text fragments into lines by their position on the page, escapes every special character, and writes the result as a well-formed XML document — a root element you name, a metadata block with the source file name and page count, then one <page> element per PDF page, each holding the page's text as <line> elements, or <paragraph> elements in paragraph mode. Before the download is offered, the page re-parses the output with the browser's own strict XML parser, so a broken file is never handed to you.
The built-in sample is a 3-page document: page 1 is an invoice header with four lines, page 2 is a short report with six lines, page 3 is a closing note with three lines — plus a title line on each page. Convert it in line mode with the root element document and you get:
| Setting | Result |
|---|---|
| Pages | 3 <page> elements, numbered 1 to 3 |
| Lines | 16 <line> elements in total (13 content lines + 3 page titles) |
| Root element | <document> — rename it to match your schema |
| Metadata | Source file name, page count, conversion date |
| Validity | Parses cleanly — verified with the browser's XML parser |
<?xml version="1.0" encoding="UTF-8"?>
<document>
<metadata>
<source>sample-three-pages.pdf</source>
<pageCount>3</pageCount>
<converted>2026-11-21</converted>
</metadata>
<page number="1">
<line>Invoice INV-2026-114</line>
<line>Billed to: Northwind Traders</line>
</page>
…
</document>
That is the shape of the classic use: an invoice, a contract or a report whose text needs to land in a database or a pipeline without anyone retyping it. For tables and forms, line mode keeps the row structure; for prose, paragraph mode gives you flowing text.
By the numbers: XML has been the W3C's standard for structured data since 1998, and it is still the format behind RSS feeds, SVG graphics, Office documents and most enterprise integrations. A PDF text layer is typically a few kilobytes per page, so even a 200-page report converts to XML in seconds — the whole job is text, no rendering involved.
| Need | Pick | Why |
|---|---|---|
| Invoices, tables, forms | Line mode | Line breaks carry the row structure |
| Reports, articles, contracts | Paragraph mode | Flowing text, split at blank lines |
| Feed a database loader | Line mode | One element per line maps to one row |
| Feed an XSLT stylesheet | Either | Both are well-formed; pick the shape your stylesheet expects |
| Archive a document | Line mode + metadata | Keeps the most structure for later |
If a line comes out joined to its neighbour, the cause is usually the PDF itself: the text layer stores fragments in drawing order, not reading order, and two columns can interleave. Line mode shows you exactly what the PDF holds — nothing is silently reordered.
The big PDF suites — iLovePDF, Smallpdf and Sejda — do not offer a PDF to XML tool at all; their text tools stop at plain-text extraction. The converters that do offer it, such as Convertio and CloudConvert, upload your document, convert it on a server, and email or link the result — and the output is often a flat dump of text with no page structure at all. This tool extracts with pdf.js and structures the text on your device, so there is no cap, no email step and no upload, and the output keeps the page structure with a metadata block. The honest limit is the PDF itself: a scanned PDF has no text layer, so there is nothing to extract until it has been through OCR.
A scan is a picture of text, not text. This tool extracts the text layer only — run the PDF through an OCR tool first to add a text layer, then convert the OCR'd copy here.
PDF stores text fragments in drawing order, not reading order. In two-column layouts, lines from both columns can mix. Line mode shows the truth; reordering is a job for a human or a layout-aware parser.
XML carries text and structure, not bold, italics or font sizes. If you need the look of the document, convert to HTML or an image format instead.
A password-protected PDF cannot be read until it is unlocked. Unlock it first with our unlock tool, then convert the unlocked copy.
Yes — unlimited PDFs, forever. No trial, no watermark, no account, no payment step. The conversion runs entirely in your browser.
No. Your PDF is read and converted 100% in your browser and never leaves your device. Check the Network tab: nothing is sent to any server.
A well-formed XML document: a root element you name, a metadata block with the source file name and page count, then one <page> element per PDF page, each holding the page's text as <line> elements — or <paragraph> elements if you pick paragraph mode. Special characters are escaped, so the output always parses.
Yes. Every special character (&, <, >, quotes) is escaped, element names are sanitised, and the page checks the output with the browser's own strict XML parser before offering the download. If it did not parse, the tool would tell you instead of handing you a broken file.
Line mode keeps every printed line of the PDF as its own <line> element — best for invoices, tables and forms, where the line breaks carry meaning. Paragraph mode joins lines into <paragraph> elements, split where the PDF leaves a blank line — best for reports, articles and contracts, where you want flowing text.
No — a scanned PDF has no text layer, only pictures of text, so there is nothing to extract. Run the PDF through an OCR tool first to add a text layer, then convert the OCR'd copy here.
Yes. The XML is plain, well-formed UTF-8 with no proprietary extensions, so any XML parser, database loader, XSLT stylesheet or data pipeline can read it. Rename the root element to match your schema before converting.
Format: XML 1.0, Fifth Edition, W3C Recommendation, 2008. Extraction: pdf.js 3.11.174 (Mozilla). Sample document: pdf-lib 1.17. PDF format: ISO 32000-1:2008. Tested 21 November 2026 on the built-in 3-page sample document (3 pages, 16 lines — output verified to parse with the browser's strict XML parser). Text extraction follows the PDF's own text layer: multi-column layouts may interleave lines, and scanned PDFs with no text layer produce no text.
Need plain text instead? Our Extract Text from PDF tool gives you the raw text. Need JSON? PDF to JSON structures the same text as JSON.
Educational content only. Nothing on this site is legal or professional advice.