我是新手,在将图像文件打印为PDF时遇到问题
我在github上遵循了Mr.DavBfr的示例
[在此处输入图片描述] [1]
[在此处输入图片描述] [2]
这是我的代码
Future<void> _printScreenShot() async {
String path;
print('haivnprint $path');
path =
'/storage/emulated/0/Android/data/example.send_mail/files/Pictures/scaled_1571112606813.png';
final ByteData bytes = fileToByte(path);
Printing.layoutPdf(onLayout: (PdfPageFormat format) {
final pdf.Document document = pdf.Document();
var screenSize = MediaQuery
.of(previewContainer.currentContext)
.size;
var width = screenSize.width.toInt();
var height = screenSize.height.toInt();
final PdfImage image = PdfImage(document.document,
image: bytes.buffer.asUint8List(),
width: width,
height: height);
document.addPage(pdf.Page(
pageFormat: format,
build: (pdf.Context context) {
return pdf.Center(
child: pdf.Expanded(
child: pdf.Image(image),
),
); // Center
})); // Page
return document.save();
});
}
我的输入图片和结果 https://i.stack.imgur.com/QawH0.jpg https://i.stack.imgur.com/VPEmU.jpg