0

How to add a Round shape image in flutter pdf.

my image Container code is

Container(
                        decoration: const BoxDecoration(
                          shape: BoxShape.circle,
                        ),
                        child: Image(
                          image,
                          height: 70,
                          width: 70,
                        )),

I also used DecorationImage but this is not working

 Container(
                        decoration: BoxDecoration(
                            shape: BoxShape.circle,
                            image: DecorationImage(
                                image: image, fit: BoxFit.cover))),

These 2 methods are not working

What should I do?

Gwhyyy
  • 7,554
  • 3
  • 8
  • 35
Mari Selvan
  • 55
  • 1
  • 9

2 Answers2

1

Check this link it could be helpfull https://github.com/DavBfr/dart_pdf/blob/master/demo/lib/examples/resume.dart

  pw.ClipOval(
                      child: pw.Container(
                        width: 100,
                        height: 100,
                        color: lightGreen,
                        child: pw.Image(profileImage),
                      ),
                    ),
Benjamin
  • 21
  • 1
  • 3
0

There is a flutter package that will let you create flutter UI widgets inside your PDf https://pub.dev/packages/pdf/example

here is an example:

import package

import 'package:pdf/pdf.dart';
import 'package:pdf/widgets.dart' as pw;
  
Future<void> createMyPDF() async {
  final pdf = pw.Document();
  final image = pw.MemoryImage(
    File('image.jpg').readAsBytesSync(),
  );

  pdf.addPage(pw.Page(
      // build PDF UI
      build: (pw.Context context) => pw.Center(
            child: pw.Container(
              decoration: pw.BoxDecoration(
                border: pw.Border.all(color: PdfColors.black),
              ),
              child: pw.Image(image),
            ),
          )));
  // save my pdf as exapmle.pdf
  final file = File('example.pdf');
  //write file in storage
  await file.writeAsBytes(await pdf.save());
}

call the function on any event to save pdf file

Mashood .H
  • 926
  • 6
  • 16