+}
+
+static void
+add_footnote_page (struct render_pager *p, const struct render_page *body)
+{
+ const struct table *table = body->table;
+ int nc = table_nc (table);
+ int nr = table_nr (table);
+ int footnote_idx = 0;
+ struct tab_table *t;
+ int x, y;
+
+ if (!body->n_footnotes)
+ return;
+
+ t = tab_create (2, body->n_footnotes);
+ for (y = 0; y < nr; y++)
+ for (x = 0; x < nc; )
+ {
+ struct table_cell cell;
+
+ table_get_cell (table, x, y, &cell);
+ if (y == cell.d[V][0])
+ {
+ size_t i;
+
+ for (i = 0; i < cell.n_contents; i++)
+ {
+ const struct cell_contents *cc = &cell.contents[i];
+ size_t j;
+
+ for (j = 0; j < cc->n_footnotes; j++)
+ {
+ const char *f = cc->footnotes[j];
+
+ tab_text (t, 0, footnote_idx, TAB_LEFT, "");
+ tab_footnote (t, 0, footnote_idx, "(none)");
+ tab_text (t, 1, footnote_idx, TAB_LEFT, f);
+ footnote_idx++;
+ }
+ }
+ }
+ x = cell.d[H][1];
+ table_cell_free (&cell);
+ }
+ render_pager_add_table (p, &t->table);
+}
+
+/* Creates and returns a new render_pager for rendering TABLE_ITEM on the
+ device with the given PARAMS. */
+struct render_pager *
+render_pager_create (const struct render_params *params,
+ const struct table_item *table_item)
+{
+ const char *caption = table_item_get_caption (table_item);
+ const char *title = table_item_get_title (table_item);
+ const struct render_page *body_page;
+ struct render_pager *p;
+
+ p = xzalloc (sizeof *p);
+ p->params = params;
+
+ /* Title. */
+ if (title)
+ render_pager_add_table (p, table_from_string (TAB_LEFT, title));
+
+ /* Body. */
+ body_page = render_pager_add_table (p, table_ref (table_item_get_table (
+ table_item)));
+
+ /* Caption. */
+ if (caption)
+ render_pager_add_table (p, table_from_string (TAB_LEFT, caption));
+
+ /* Footnotes. */
+ add_footnote_page (p, body_page);
+
+ render_pager_start_page (p);
+