如何在flutter PDF中添加圆形图像



如何在flutter pdf中添加圆形图像。

my imageContainercode is

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

我也用了DecorationImage,但这不起作用

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

这两个方法都不起作用

我该怎么办?

点击此链接可能会有帮助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),
),
),

有一个flutter包,可以让您在PDf中创建flutter UI小部件https://pub.dev/packages/pdf/example

下面是一个例子:

导入包

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

在任意事件上调用函数保存PDF文件

最新更新