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

# PDF Export - Columns

PDF Export includes the currently displayed columns in their displayed order by default. Export parameters can include hidden columns, choose a specific column set, suppress headers, or include the Row Numbers column.

## Column Headers

Column headers and column-group headers are exported by default. Set `skipColumnHeaders=true` or `skipColumnGroupHeaders=true` to omit the corresponding header rows.

```js
api.exportDataAsPdf({
    skipColumnHeaders: false,
    skipColumnGroupHeaders: true,
});
```

When headers are included, `processHeaderCallback` and `processGroupHeaderCallback` can customise their exported text.

## Hidden And Specific Columns

Hidden columns are omitted by default. Set `allColumns=true` to export every primary column in `columnDefs` order, including hidden columns.

```js
api.exportDataAsPdf({
    allColumns: true,
});
```

Use `columnKeys` when only a specific set of columns should be exported. The supplied column keys or Column objects also determine their export order.

```js
api.exportDataAsPdf({
    columnKeys: ['customer', 'product', 'total'],
});
```

When pivot mode is active, PDF Export uses the currently displayed pivot result columns. Hidden or collapsed pivot result columns are not added by `allColumns`.

## Column Groups

Displayed column-group headers are rendered as PDF header rows. A PDF cannot contain interactive collapsible column groups, so exported groups are a static representation of the selected columns.

Columns hidden by a closed grid group are omitted by default. Use `allColumns=true` to include every primary column, or use `columnKeys` for precise control over the exported column set.

## Row Numbers

The Row Numbers column is not exported by default, even when it is displayed in the grid. Set `exportRowNumbers=true` to include it.

```js
api.exportDataAsPdf({
    exportRowNumbers: true,
});
```

When `columnWidth` is omitted, the exported Row Numbers column is sized automatically from its contents. A global or per-column `columnWidth` configuration can override this behaviour.

The example below demonstrates header suppression, visible or hidden column selection, and Row Numbers export.

#### PDF Export - Columns

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

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

ModuleRegistry.registerModules([
  ClientSideRowModelModule,
  RowNumbersModule,
  PdfExportModule,
]);

interface OrderData {
  customer: string;
  country: string;
  product: string;
  quantity: number;
  total: number;
  internalReference: string;
}

const rowData: OrderData[] = [
  {
    customer: "Atlas Design",
    country: "United Kingdom",
    product: "Mechanical Keyboard",
    quantity: 12,
    total: 1794,
    internalReference: "Priority account",
  },
  {
    customer: "Northstar Labs",
    country: "United States",
    product: "USB-C Dock",
    quantity: 8,
    total: 1752,
    internalReference: "Renewal due",
  },
  {
    customer: "Horizon Studio",
    country: "Australia",
    product: "Studio Monitor",
    quantity: 6,
    total: 4134,
    internalReference: "New customer",
  },
];

let gridApi: GridApi<OrderData>;

const gridOptions: GridOptions<OrderData> = {
  columnDefs: [
    {
      headerName: "Customer Details",
      children: [
        { field: "customer", minWidth: 160 },
        { field: "country", minWidth: 140 },
      ],
    },
    {
      headerName: "Order Details",
      children: [
        { field: "product", minWidth: 180 },
        { field: "quantity" },
        { field: "total", valueFormatter: (params) => `$${params.value}` },
      ],
    },
    {
      field: "internalReference",
      headerName: "Internal Reference",
      hide: true,
    },
  ],
  defaultColDef: {
    flex: 1,
    minWidth: 100,
  },
  rowNumbers: true,
  rowData,
};

function isChecked(id: string): boolean {
  return document.querySelector<HTMLInputElement>(`#${id}`)!.checked;
}

function onBtExport() {
  const columnSet =
    document.querySelector<HTMLSelectElement>("#columnSet")!.value;
  const params: PdfExportParams = {
    skipColumnGroupHeaders: isChecked("skipColumnGroupHeaders"),
    skipColumnHeaders: isChecked("skipColumnHeaders"),
    exportRowNumbers: isChecked("exportRowNumbers"),
    columnWidth: "auto",
  };

  if (columnSet === "all") {
    params.allColumns = true;
  } else if (columnSet === "specific") {
    params.columnKeys = ["customer", "product", "total"];
  }

  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 - Columns](https://www.ag-grid.com/examples/pdf-export-columns/pdf-export-columns/typescript/)

## Column Widths

The `columnWidth` option accepts:

- `'grid'` to use the current grid width.
- `'auto'` to measure the exported header and body content.
- A number to use a fixed width in points.
- A callback to configure each exported column independently.

When `columnWidth` is omitted, regular columns use `'grid'` and the Row Numbers column uses `'auto'`. A `columnWidth` value overrides those defaults; a callback result overrides the default for that column. Returning `null` or `undefined` from the callback uses the column's default mode.

Auto widths are measured before page scaling. If the combined widths exceed the printable page width, every column is reduced proportionally. Smaller tables are not stretched. Horizontal pagination and automatically expanding the page size are not supported.

PDF layout dimensions use points, where 72 points equal one inch.

#### Widths And Autosizing

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

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

ModuleRegistry.registerModules([
  ClientSideRowModelModule,
  RowNumbersModule,
  PdfExportModule,
]);

interface ProductData {
  sku: string;
  product: string;
  description: string;
  units: number;
  unitPrice: number;
}

const rowData: ProductData[] = [
  {
    sku: "KB-104",
    product: "Mechanical Keyboard",
    description:
      "Low-profile wireless keyboard with hot-swappable switches and multi-device pairing.",
    units: 128,
    unitPrice: 149.5,
  },
  {
    sku: "DS-220",
    product: "USB-C Dock",
    description:
      "Twelve-port desktop dock supporting dual displays, Ethernet, audio, and power delivery.",
    units: 76,
    unitPrice: 219,
  },
  {
    sku: "MN-340",
    product: "Studio Monitor",
    description:
      "Colour-accurate 27-inch display intended for design, photography, and video workflows.",
    units: 42,
    unitPrice: 689,
  },
];

let gridApi: GridApi<ProductData>;

const gridOptions: GridOptions<ProductData> = {
  columnDefs: [
    { field: "sku", width: 100 },
    { field: "product", width: 180 },
    { field: "description", minWidth: 260 },
    { field: "units", width: 100 },
    {
      field: "unitPrice",
      headerName: "Unit Price",
      width: 120,
      valueFormatter: (p) => `$${p.value}`,
    },
  ],
  defaultColDef: { resizable: true },
  rowNumbers: true,
  rowData,
};

function onBtExport() {
  const widthMode =
    document.querySelector<HTMLSelectElement>("#widthMode")!.value;
  const params: PdfExportParams = { exportRowNumbers: true };

  if (widthMode === "custom") {
    params.columnWidth = ({ column }) => {
      const columnId = column?.getColId();
      if (columnId === ROW_NUMBERS_COLUMN_ID) {
        return "auto";
      }
      if (columnId === "description") {
        return 220;
      }
      if (columnId === "sku" || columnId === "units") {
        return 70;
      }
      return "auto";
    };
  } else {
    params.columnWidth = widthMode === "grid" ? "grid" : "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: Widths And Autosizing](https://www.ag-grid.com/examples/pdf-export-columns/pdf-widths-autosizing/typescript/)
