如何在PdfGrid中插入图像? Flutter

yx2lnoni  于 2023-05-08  发布在  Flutter
关注(0)|答案(2)|浏览(242)

我需要插入一个图像到PdfGriD(细胞)使用BackgroundImage,但不工作。

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));

brccelvz

brccelvz1#

我们可以通过使用单元格样式中的BackgroundImage属性将图像插入到PdfGrid中。它在网格单元格中正确添加了一个图像。请找到下面的代码片段,

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();

示例:https://www.syncfusion.com/downloads/support/directtrac/general/pd/GridOutput921468422
UG:https://help.syncfusion.com/flutter/pdf/working-with-images
表:https://help.syncfusion.com/flutter/pdf/working-with-tables

qvk1mo1f

qvk1mo1f2#

这对我不起作用。图像未显示在表中。

相关问题