Pagecraft

pdf-to-markdown

PDF to Markdown

Turn a PDF back into Markdown, with its headings, lists and tables.

Reads
a PDF — application/pdf
Writes
one file — Markdown
Tool page
/pdf-to-markdown

Example

Get a report into a form you can edit in a text editor.

Given

  • report.pdf — a PDF of written text

From code

            import { loadDocument, runOperation } from '@pagecraft/core';

const report = await loadDocument({ bytes, name: 'report.pdf' });

const [output] = await runOperation('pdf-to-markdown', [report], {
  headings: true,
  tables: true,
});
          

From a shell

            pagecraft pdf-to-markdown report.pdf
          

What comes back

One Markdown file, containing “Quarterly report”.

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 convert.

Default: 'all'

headings--headings

boolean

Find headings

Treat larger and bolder lines as headings.

Default: true

tables--tables

boolean

Find tables

Turn ruled and aligned columns into Markdown tables.

Default: true

What it cannot do

  • A PDF does not record what was a heading, a list or a table; it records type at sizes in places. All of that is inferred from the page, and a page laid out unusually will be read unusually.
  • Markdown has no table without a heading row, so a table that has no obvious one is written with its first row as the heading.
  • A scanned page holds a picture of words. Run OCR over it first.
  • What Markdown cannot say is dropped rather than approximated: colour, exact position, the page a thing was on, and anything drawn rather than typed.