2

I need insert an image into the PdfGriD(Cell) using the BackgroundImage but is not working.

PdfBitmap pBmp = PdfBitmap(await _readImageData('1.jpg'));

    PdfGridRow row2 = grid2.rows.add();
    row2.cells[0].value = 'Velocidad - v [fpm]';
    row2.cells[1].style.backgroundImage = pBmp;
...
grid2.draw(page: page, bounds: const Rect.fromLTWH(0, 130, 500, 500));

enter image description here

Md. Yeasin Sheikh
  • 54,221
  • 7
  • 29
  • 56

2 Answers2

1

We can insert an image into the PdfGrid by using the BackgroundImage property in the Cell style. Its added a image in a grid cell properly. Please find the below code snippet,

PdfDocument document = PdfDocument();

//Create a PdfGrid class

PdfGrid grid = PdfGrid();

//Add the columns to the grid

grid.columns.add(count: 3);

//Add header to the grid

grid.headers.add(1);

//Add the rows to the grid

PdfGridRow header = grid.headers[0];

header.cells[0].value = 'Employee ID';

header.cells[1].value = 'Employee Name';

header.cells[2].value = 'Salary';

//Add rows to grid

PdfGridRow row = grid.rows.add();

row.cells[0].value = 'E01';

row.cells[1].value = 'Clay';

row.cells[2].value = '\$10,000';

final PdfImage image = PdfBitmap(File('E://logo.png').readAsBytesSync());

row = grid.rows.add();

row.height = 30;

row.cells[0].value = 'E02';

row.cells[1].style.backgroundImage = image;

row.cells[1].value = "";

row.cells[2].value = '\$12,000';

row = grid.rows.add();

row.cells[0].value = 'E03';

row.cells[1].value = 'John';

row.cells[2].value = '\$14,000';

//Draw the grid

grid.draw(
      page: document.pages.add(), bounds: const Rect.fromLTWH(0, 0, 0, 0));

File('E://Flutter/GridOutput.pdf').writeAsBytes(document.save());

document.dispose();

Sample: https://www.syncfusion.com/downloads/support/directtrac/general/pd/GridOutput921468422

UG: https://help.syncfusion.com/flutter/pdf/working-with-images

Tables: https://help.syncfusion.com/flutter/pdf/working-with-tables

Dharman
  • 30,962
  • 25
  • 85
  • 135
gowtham raj
  • 187
  • 2
0

this doesn't work for me. The image isn't showed in the table.

Timo
  • 1
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 03 '23 at 21:13