I've been been trying to print an existing pdf file which is in sd card. So i added printing package to my flutter project to print pdf files.
Printing package link
I checked their documentation and i can't find a way to load and print pdf.
Fyi, i can create a pdf from image, text or whaetever it is and pass it to the Printing function. That works as anticipated.
final pdf = Document();
pdf.addPage(Page(
pageFormat: PdfPageFormat.a4,
build: (Context context) {
return Center(
child: Text("Hello World"),
);
})
);
await Printing.layoutPdf(onLayout: (PdfPageFormat format) async => pdf.save());
Any help to load existing pdf and print would be appreciable
Thanks
I finally find a way to print pdf using printing plugin.
You can directly print pdf by giving the online pdf url
To do so, just use the following dart snippet
http.Response response = await http.get('http://www.africau.edu/images/default/sample.pdf');
var pdfData = response.bodyBytes;
await Printing.layoutPdf(onLayout: (PdfPageFormat format) async => pdfData);
Don't forget to import http plugin
import 'package:http/http.dart' as http;
Thanks everyone for the help
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With