Reputation: 996
I am trying to print a PDF from flutter. I pubget the printing package via pub.dev.
https://pub.dev/packages/printing
After running the app following the example, press the printer icon button to move the screen.
I'm trying to fix the Save as PDF part shown above. I couldn't find the UI part even if I searched along the class.
I noticed that the view is switched through the _print method of the PdfPreview class, but after that, I couldn't find where to make the UI and make it work.
Do you know a dart file or class that makes UI?
main.dart
import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'package:pdf/pdf.dart';
import 'package:pdf/widgets.dart' as pw;
import 'package:printing/printing.dart';
import 'package:http/http.dart' as http;
Future<void> main() async {
runApp(MyApp('Printing Demo'));
}
class MyApp extends StatelessWidget {
MyApp(this.title, {Key? key}) : super(key: key);
final String title;
PdfDocument? _doc;
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(title: Text(title)),
body: PdfPreview(
build: (format) => _generatePdf(format, title),
),
),
);
}
Future<Uint8List> _generatePdf(PdfPageFormat format, String title) async {
final pdf = pw.Document(version: PdfVersion.pdf_1_5, compress: true);
final font = await PdfGoogleFonts.nunitoExtraLight();
pdf.addPage(
pw.Page(
pageFormat: format,
build: (context) {
return pw.Column(
children: [
pw.SizedBox(
width: double.infinity,
child: pw.FittedBox(
child: pw.Text(title, style: pw.TextStyle(font: font)),
),
),
pw.SizedBox(height: 20),
pw.Flexible(child: pw.FlutterLogo())
],
);
},
),
);
return pdf.save();
}
}
Upvotes: 0
Views: 1558
Reputation: 539
You cant change printing view - is handled by system. I belive this is how this package works - it sends data to another Intenet
Upvotes: 1