Home > Mobile >  I want to insert the photo taken with the camera into a cell of the table in the pdf. But I am getti
I want to insert the photo taken with the camera into a cell of the table in the pdf. But I am getti

Time:03-13

// I want to insert the photo taken with the camera into a cell of the table in the pdf. But I am getting the following error code.

Reloaded 1 of 1223 libraries in 6.711ms.
E/flutter (21256): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: Unable to load asset: File: '/data/user/0/com.example.syncsqftomysql/cache/a7844dd4-e07d-4e16-bdb0-c6618dde63eb-972127577.jpg'
E/flutter (21256): #0      PlatformAssetBundle.load (package:flutter/src/services/asset_bundle.dart:224:7)
E/flutter (21256): <asynchronous suspension>
E/flutter (21256): #1      _QrCodeState._readImageDatatoPDF (package:upmp/bysuygformu.dart:1665:18)
E/flutter (21256): <asynchronous suspension>
E/flutter (21256): #2      _QrCodeState._createPDF (package:upmp/bysuygformu.dart:1714:15)
E/flutter (21256): <asynchronous suspension>
E/flutter (21256): 

//Some of my codes are as follows. An example application may also be useful to //me.

Future<Uint8List> _readImageDatatoPDF(String name) async {
    final data = await rootBundle.load(imageFile.toString());
    return data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes);
  }

Future<void> _createPDF() async {
     PdfDocument document = PdfDocument();
    final page = document.pages.add();
    PdfGrid grid = PdfGrid();
    grid.style = PdfGridStyle(
        font: PdfStandardFont(PdfFontFamily.helvetica, 30),
        cellPadding: PdfPaddings(left: 5, right: 2, top: 2, bottom: 2));
    grid.columns.add(count: 3);
    grid.headers.add(1);
    PdfGridRow header = grid.headers[0];
    header.cells[0].value = '0';
    header.cells[1].value = 'Firma Adresi';
    header.cells[2].value = 'aaa';

    PdfGridRow row = grid.rows.add();
    row.cells[0].value = '1';
    row.cells[1].value = 'Depolar';
    row.cells[2].value = 'K-Ortrine';

    row = grid.rows.add();
    row.cells[0].value = '2';
    row.cells[1].value = 'Merkez';
    row.cells[2].value = 'Icon';

    row = grid.rows.add();`enter code here`
    row.cells[0].value = '3';
    row.cells[1].value = 'Taha';
      PdfGridCell cell2 = row.cells[2];
     grid.rows[2].height = 200;
     cell2.imagePosition = PdfGridImagePosition.stretch;

    cell2.style.backgroundImage =
     
    PdfBitmap(await _readImageDatatoPDF(
      pic.toString()));
     Rect.fromLTWH(0, 0, 0, 0);
       grid.draw(page: page, bounds: const Rect.fromLTWH(0, 0, 0, 0));

    List<int> bytes = document.save();
       document.dispose();`enter code here`
    saveAndLaunchFile(bytes, 'cikti.pdf');
  }

I want to insert the photo I took from the camera into a cell of the table in the pdf. I want to insert the photo I took from the camera into a cell of the table in the pdf. I want to insert the photo I took from the camera into a cell of the table in the pdf.

CodePudding user response:

cell2.style.backgroundImage =

This is where I would start. You are not using the photo as an object. You have chosen to use the image as a style. The style would require calling the storage location vs treating the photo as an object.

  • Example. I painted the wall. Error where is the paint can.
  • Example. I put the paint can in the cubby hole. View/Display paint can.

CodePudding user response:

Under the command line you mentioned, I can add the image in the image folder with the asset to the cell in the pdf table. But I couldn't add the photo I took from the camera.

 PdfGridCell cell2 = row.cells[2];
 grid.rows[2].height = 200;
 cell2.imagePosition = PdfGridImagePosition.stretch;
 cell2.style.backgroundImage =
    PdfBitmap(await  _readImageData( 'urban-logo.jpg'),);
    Rect.fromLTWH(0, 0, 0, 0);
grid.draw(page: page, bounds: const Rect.fromLTWH(0, 0, 0, 0)) ;

Can you write your answer in a little more detail?enter code here

  • Related