Paperful Icon
Paperfuldocs
Papers

Read the paper graph

Load a paper's nodes in reading order and move between them.

The Paper Graph is the structured content of a paper: an ordered list of nodes such as titles, paragraphs and tables.

Load the graph

const graph = await paperful.papers.graph("00000000-0000-0000-0000-000000000000");

for (const node of graph.nodes) {
  console.log(node.position, node.type, node.page);
}

Load every node

Large papers are loaded one page at a time. Each call to next() adds the following page to graph.nodes, and previous() adds the page before it.

const graph = await paperful.papers.graph("00000000-0000-0000-0000-000000000000");

while (graph.cursor?.next) {
  await graph.next();
}

console.log(graph.nodes.length === graph.total);

Filter nodes

Only load nodes of some types, or from a single page of the document. Filters are kept when loading more nodes with next() and previous().

const graph = await paperful.papers.graph("00000000-0000-0000-0000-000000000000",
  {
    type: ["table", "chart"],
    page: 3,
  }
);

See the List nodes API reference for every type.

Read a node

Each node includes:

FieldDescription
idThe node's ID.
typeThe node's type, such as paragraph_title, text or table.
textThe plain text content of the node.
pageThe page the node is on.
positionThe node's position in the paper's reading order.
bboxWhere the node is on the page.
refsThe text entries that make up the node, with their font, size and position.
renderA signed URL to an image of the node's region.
dataData specific to the node's type, see below.

Node data

Tables, charts, images and titles are enriched with extra data. Use is() to check a node's type, which also gives you the right type for data in TypeScript.

for (const node of graph.nodes) {
  if (node.is("table")) {
    console.log(node.data?.summary, node.data?.rows, node.data?.columns);
  }

  if (node.is("image", "header_image", "footer_image")) {
    console.log(node.data?.alt);
  }
}
TypeData
tablesummary, tags, rows, columns, cells, insights and importance.
chartThe chart type, title, alt, summary, tags, source, insights and importance.
image, header_image, footer_imageThe image type, title, alt, tags, detected objects and entities, and importance.
doc_title, paragraph_titleThe heading level.
Any other typeAlways null.

data is null until the node is enriched.

Get a node

Retrieve a single node by its ID, for example a node from a search result. It doesn't need to be loaded in the graph yet.

const graph = await paperful.papers.graph("00000000-0000-0000-0000-000000000000");

const node = await graph.node("00000000-0000-0000-0000-000000000000");

const context = await node.context();

A node retrieved this way isn't added to graph.nodes. Use its context to read around it, since next() and previous() only work for nodes loaded in the graph.

Move between nodes

Each node can reach its neighbours. Missing pages are loaded automatically. To load several neighbours at once, use the node's context.

const node = graph.nodes[0];

const next = await node.next();
const previous = await node.previous(); // undefined at the start of the paper

Options

Prop

Type

On this page