---
title: "PDF Export - Page Setup"
enterprise: true
framework: javascript
version: "36.1.0"
---

# PDF Export - Page Setup

Configure the PDF page size, orientation, margins, and repeated table headers using the `page` and `repeatHeader` export options. Page dimensions and margins use points, where 72 points equal one inch.

## Page Size And Orientation

The default page is A4 landscape with a 36-point margin on every side. Use named `A4` or `Letter` page sizes, or provide explicit dimensions. Custom dimensions are normalised to the requested orientation.

```js
api.exportDataAsPdf({
    page: {
        size: { width: 720, height: 540 },
        orientation: 'landscape',
        margin: { top: 36, right: 24, bottom: 36, left: 24 },
    },
});
```

For named sizes, changing `orientation` rotates the page dimensions. For custom sizes, the supplied dimensions are normalised so the wider side is used for landscape and the taller side is used for portrait.

## Page Margins

Set `page.margin` to one number for every side, or provide individual `top`, `right`, `bottom`, and `left` values.

```js
api.exportDataAsPdf({
    page: {
        margin: 24,
    },
});
```

Margins reduce the printable area available to the document title and table. Exported columns are scaled down proportionally when their combined widths exceed the available width.

## Repeating Table Headers

Table header rows repeat when body rows continue onto another page by default. Set `repeatHeader=false` to render them only on the first page.

A repeated header is omitted when it cannot fit together with the next row or row fragment. Page headers and footers are not currently supported.

The example below lets you change the page size, orientation, margins, and repeated-header behaviour before exporting.

#### PDF Export - Page Setup

```ts
import {
  ClientSideRowModelModule,
  GridApi,
  GridOptions,
  ModuleRegistry,
  PdfExportParams,
  PdfPageOrientation,
  PdfPageSize,
  createGrid,
  enableDevValidations,
} from "ag-grid-community";
import { PdfExportModule } from "ag-grid-enterprise";

// Enable extended validations only for development
if (process.env.NODE_ENV !== "production") {
  enableDevValidations();
}

ModuleRegistry.registerModules([ClientSideRowModelModule, PdfExportModule]);

interface InventoryData {
  item: string;
  category: string;
  warehouse: string;
  quantity: number;
  status: string;
}

// Build the rows in the declaration itself: the framework generators inline the `rowData` grid
// option's initialiser and drop the declaration, so a separately-populated array (a top-level
// `rowData.push(...)` loop) is left referencing a name that no longer exists.
const rowData: InventoryData[] = Array.from({ length: 40 }, (_, index) => {
  const categories = ["Accessories", "Displays", "Networking", "Storage"];
  const warehouses = ["London", "Chicago", "Singapore"];
  const itemNumber = index + 1;

  return {
    item: `Item ${itemNumber}`,
    category: categories[index % categories.length],
    warehouse: warehouses[index % warehouses.length],
    quantity: 20 + itemNumber * 3,
    status: itemNumber % 4 === 0 ? "Reorder" : "Available",
  };
});

let gridApi: GridApi<InventoryData>;

const gridOptions: GridOptions<InventoryData> = {
  columnDefs: [
    { field: "item", minWidth: 170 },
    { field: "category", minWidth: 130 },
    { field: "warehouse", minWidth: 120 },
    { field: "quantity" },
    { field: "status" },
  ],
  defaultColDef: {
    flex: 1,
    minWidth: 100,
  },
  rowData,
};

function getPageSize(): PdfPageSize {
  const pageSize =
    document.querySelector<HTMLSelectElement>("#pageSize")!.value;

  if (pageSize === "Letter") {
    return "Letter";
  }
  if (pageSize === "custom") {
    return { width: 420, height: 300 };
  }
  return "A4";
}

function getPageOrientation(): PdfPageOrientation {
  return document.querySelector<HTMLSelectElement>("#orientation")!.value ===
    "portrait"
    ? "portrait"
    : "landscape";
}

function getPageMargin(): number {
  const margin = document.querySelector<HTMLSelectElement>("#margin")!.value;

  if (margin === "compact") {
    return 18;
  }
  if (margin === "wide") {
    return 54;
  }
  return 36;
}

function onBtExport() {
  const params: PdfExportParams = {
    documentTitle: "Quarterly Inventory",
    page: {
      size: getPageSize(),
      orientation: getPageOrientation(),
      margin: getPageMargin(),
    },
    repeatHeader:
      document.querySelector<HTMLInputElement>("#repeatHeader")!.checked,
    columnWidth: "auto",
  };

  gridApi.exportDataAsPdf(params);
}

gridApi = createGrid(
  document.querySelector<HTMLElement>("#myGrid")!,
  gridOptions,
);

if (typeof window !== "undefined") {
  // Attach external event handlers to window so they can be called from index.html
  (<any>window).onBtExport = onBtExport;
}
```

[Live example: PDF Export - Page Setup](https://www.ag-grid.com/examples/pdf-export-page-setup/pdf-export-page-setup/typescript/)
