Pagecraft

pdf-to-html

PDF to HTML

Turn a PDF into HTML that is marked up as a document, not painted as a page.

Reads
a PDF — application/pdf
Writes
one file — HTML
Tool page
/pdf-to-html

Example

Put a document on an intranet page without a PDF viewer.

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-html', [report], {
  standalone: true,
});
          

From a shell

            pagecraft pdf-to-html report.pdf
          

What comes back

One HTML 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 HTML tables.

Default: true

standalone--standalone

boolean

A whole page

Write a complete HTML document rather than the markup on its own.

Default: true

What it cannot do

  • This is the document, not a photograph of it: headings, lists, tables and emphasis survive; the exact position, the colours and anything drawn rather than typed do not.
  • A PDF does not record what was a heading or a list, so all of it is inferred from the size, the weight and the layout of the type.
  • Pictures on the page are not carried across. Use Extract images to get them.
  • A scanned page holds a picture of words. Run OCR over it first.