Core Features

Advanced Features

Angular Data GridPDF Export - Images

Version 36.2.0
Enterprise

PDF Export can embed JPEG and PNG images in grid cells, page headers, and page footers. Images are embedded directly in the generated document without third-party libraries.

Images In Grid Cells Copy Link

Load each image as a base64 string before export, then use addImageToCell to provide an image for an exported body cell. The callback receives the final exported cell value, row node, and column. Return the image together with the text that should appear alongside it.

<ag-grid-angular
    [addImageToCell]="addImageToCell"
    /* other grid options ... */ />

this.addImageToCell = (params) => {
    if (params.column.getColId() !== 'country') {
        return;
    }

    return {
        image: {
            id: params.node.data.countryCode,
            base64: flagImages[params.node.data.countryCode],
            imageType: 'png',
            width: 18,
            height: 12,
        },
        value: params.value,
    };
};

The image id is used to embed repeated images only once. Supply either width or height in PDF points and the image keeps its original aspect ratio; supplying both stretches the image to those exact dimensions. Use alignment to render the image before ('start', the default) or after ('end') the cell text, and gap to control the space between the image and the text.

The following example displays country flags with a Cell Renderer and exports the same flags alongside the country names in the PDF.

Cell Renderer output is not captured automatically. Use addImageToCell to explicitly provide the image data required by the PDF.

Images In Page Headers And Footers Copy Link

Set image on a PdfHeaderFooterContent entry to add a company logo or other image to a page header or footer. An entry can contain an image, text, or both.

const defaultPdfExportParams = {
    headerFooterConfig: {
        all: {
            header: [
                {
                    position: 'Left',
                    image: {
                        id: 'company-logo',
                        base64: companyLogo,
                        imageType: 'png',
                        width: 92,
                    },
                },
                {
                    position: 'Right',
                    value: 'Page &[Page] of &[Pages]',
                },
            ],
        },
    },
};

The exported page colours follow the grid theme, so a logo designed for a light page can be hard to see when the grid uses a dark theme. Supply a logo variant for each theme and select one when exporting — reading the grid's background colour at export time keeps the choice in step with the active theme.

The following example adds the AG Grid logo to every page header, selecting a light or dark logo variant from the grid's background colour.

Known Limitations Copy Link

  • PNG and JPEG are the supported formats. Typical web images work as-is, including PNG transparency, palette PNGs, and progressive JPEGs.
  • GIF, SVG, WebP, animated images, interlaced PNG, 16-bit PNG, CMYK JPEG, lossless JPEG, and image collections are not supported.
  • Cell Renderer output and images referenced by HTML or CSS are not captured automatically.
  • A cell or page header/footer entry can contain one image.
  • Images cannot currently be used on cover pages or as watermarks.
  • Images cannot currently contain hyperlink annotations.
  • Source images are embedded at their supplied resolution. Use appropriately sized images to limit the exported file size.

API Copy Link

Export Options Copy Link

headerFooterConfigCopy Link
PdfHeaderFooterConfig
Page header and footer content.
addImageToCellCopy Link
Function
Callback that provides an image for an exported body cell. Return an optional value to replace the exported cell text.

PdfImage Copy Link

Properties available on the PdfImage interface.

id requiredCopy Link
string
Identifier used to embed repeated images only once in the PDF.
base64 requiredCopy Link
string
Base64 image data, with or without a data URL prefix.
imageType requiredCopy Link
PdfImageType
Image format.
altTextCopy Link
string
Alternative text for the image.
number
Rendered width in points. When omitted, the intrinsic image width is used at 96 DPI. Setting only one of width and height preserves the aspect ratio; setting both stretches the image to those dimensions.
heightCopy Link
number
Rendered height in points. When omitted, the intrinsic image height is used at 96 DPI. Setting only one of width and height preserves the aspect ratio; setting both stretches the image to those dimensions.
alignmentCopy Link
PdfImageAlignment
default: 'start'
Image alignment relative to adjacent text.
number
default: 4
Space between the image and adjacent text in points.

PdfCellImageCallbackParams Copy Link

Properties available on the PdfCellImageCallbackParams<TData = any, TContext = any> interface.

string
The final text exported for the cell.
accumulatedRowIndexCopy Link
number
The 1-based index of the current exported row.
The row node for the exported cell.
The current column.
The grid api.
Application context as set on gridOptions.context.

PdfCellImageResult Copy Link

Properties available on the PdfCellImageResult interface.

image requiredCopy Link
PdfImage
Image rendered in the exported cell.
string | null
Text rendered alongside the image. When omitted, the exported cell text is removed.

PdfHeaderFooterTextContent Copy Link

Properties available on the PdfHeaderFooterTextContent interface.

string
Header or footer text. Supports &[Page], &[Pages], &[Date], and &[Time] placeholders.
PdfImage
Image rendered alongside the text.
positionCopy Link
'Left' | 'Center' | 'Right'
Position of the content within the printable page width. When omitted, array entries default to left, centre, and right in order.
PdfTextStyle
Text styling for this entry.

PdfHeaderFooterImageContent Copy Link

Properties available on the PdfHeaderFooterImageContent interface.

string
Header or footer text. Supports &[Page], &[Pages], &[Date], and &[Time] placeholders.
PdfImage
Image rendered alongside the text.
positionCopy Link
'Left' | 'Center' | 'Right'
Position of the content within the printable page width. When omitted, array entries default to left, centre, and right in order.
PdfTextStyle
Text styling for this entry.