Reputation: 47
I am trying to print image to mobile Bluetooth thermal printer by ESC_POS_UTIL flutter Library, the Library support only image print or Text, so my plane is to render PDF and save to a PDF file by using pdf: ^3.3.0 Library which take job done perfectly, now there is only thing that how can i convert pdf to an image file and save to phone storage in order to print with ESC_POS_UTIL by FLUTTER
Upvotes: 1
Views: 8552
Reputation: 86
native_pdf_renderer
is a flutter package that helps to render images from pdf files. Refer https://pub.dev/packages/native_pdf_renderer for more details.
Example code from package documentation:
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:native_pdf_renderer/native_pdf_renderer.dart';
void main() async {
try {
final document = await PdfDocument.openAsset('assets/sample.pdf');
final page = await document.getPage(1);
final pageImage = await page.render(width: page.width, height: page.height);
await page.close();
runApp(MaterialApp(
home: Scaffold(
body: Center(
child: Image(
image: MemoryImage(pageImage.bytes),
),
),
),
color: Colors.white,
));
} on PlatformException catch (error) {
print(error);
}
}
Upvotes: 2