Pagecraft

alt-text

Add alt text to PDF images

Write a description of each picture into the document, where a screen reader reads it.

Reads
a PDF — application/pdf
Writes
one file — PDFs
Tool page
/add-alt-text-to-pdf

Example

Describe a photograph for somebody who will hear the document rather than see it.

Given

  • illustrated.pdf — a PDF with a photograph in it

From code

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

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

const [output] = await runOperation('alt-text', [illustrated], {
  descriptions: [
    {
      page: 1,
      picture: 1,
      text: 'A warehouse floor, seen from the mezzanine.',
    },
  ],
});
          

From a shell

            pagecraft alt-text illustrated.pdf --descriptions '[{"page":1,"picture":1,"text":"A warehouse floor, seen from the mezzanine."}]'
          

What comes back

One PDF of 1 page.

This example is run by the test suite. If it stopped being true, the build would fail.

Options

descriptions--descriptionsRequired

object[]

Descriptions

Each picture, and what someone who cannot see it needs to be told.

overwrite--overwrite

boolean

Replace descriptions already in the file

Off keeps whatever the document already says about a picture.

Default: true

What it cannot do

  • A picture is named by the page it is first drawn on and its number among that page’s pictures — the same numbering Extract images uses, which is also how it names the files it gives you.
  • A picture drawn from inside a form — a stamp, a reusable header, an imported page — is described only where the document is already tagged for it, because marking it up would mark it up everywhere the form is used.
  • A picture drawn straight into the page’s instructions rather than stored as an object cannot be named or described.
  • This writes what a screen reader speaks. It does not check the rest of what makes a document accessible: reading order, headings, table headers and language are untouched.
  • A description is written as text on the picture’s own element. It is not drawn on the page, and nobody reading the page with their eyes will see it.