Pdf Component - PdfImageStyle

30 Sep 20261 minute to read

Public enum that specifies how an image is sized within a PdfGrid cell.

// Load an existing PDF document
let document: PdfDocument = new PdfDocument(data, password);
// Access the first page
let page: PdfPage = document.getPage(0);
// Create a data-source grid
let grid: PdfGrid = new PdfGrid([{ id: '1' }], [{ field: 'id' }]);
// Set the image fit mode for a cell
grid.getRow(0).cells[0].style = { imageProperties: { fitType: PdfImageStyle.fitCell } };
// Draw the grid on the page
grid.draw(page, { x: 10, y: 10, width: 240, height: 160 });
// Save the document
document.save('output.pdf');
// Destroy the document
document.destroy();
  • fitCell - Fits the image within both the available content width and height while preserving its aspect ratio.
  • fitHeight - Fits the image to the available content height while preserving its aspect ratio.
  • fitWidth - Fits the image to the available content width while preserving its aspect ratio.
  • stretch - Stretches the image to exactly fill the available content width and height, ignoring the aspect ratio.