Below is a beginner-friendly, step-by-step guide to creating a PDF app in Flutter, including complete source code.
This example shows how to generate a PDF and preview it inside the app.
What this app will do
✅ Create a PDF
✅ Add text to the PDF
✅ Save the PDF locally
✅ Open/preview the PDF
1. Create a new Flutter project
flutter create pdf_app
cd pdf_app
2. Add required dependencies
Open pubspec.yaml and add:
dependencies:
flutter:
sdk: flutter
pdf: ^3.10.7
path_provider: ^2.1.2
open_file: ^3.3.2
Then run:
flutter pub get
3. Import required packages
Open lib/main.dart and add these imports:
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:pdf/widgets.dart' as pw;
import 'package:path_provider/path_provider.dart';
import 'package:open_file/open_file.dart';
4. Full Source Code (main.dart)
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Flutter PDF App',
home: const HomePage(),
);
}
}
class HomePage extends StatelessWidget {
const HomePage({super.key});
Future<void> createPDF() async {
final pdf = pw.Document();
pdf.addPage(
pw.Page(
build: (pw.Context context) {
return pw.Center(
child: pw.Text(
'Hello! This PDF was created using Flutter 🎉',
style: pw.TextStyle(fontSize: 24),
),
);
},
),
);
final dir = await getApplicationDocumentsDirectory();
final file = File('${dir.path}/example.pdf');
await file.writeAsBytes(await pdf.save());
// Open the PDF file
await OpenFile.open(file.path);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Flutter PDF App'),
),
body: Center(
child: ElevatedButton(
onPressed: createPDF,
child: const Text('Create & Open PDF'),
),
),
);
}
}
5. Run the app
flutter run
Tap “Create & Open PDF” → The PDF will be generated and opened automatically.
Result
📄 A PDF file containing:
Hello! This PDF was created using Flutter 🎉
What you can add next
- 🧾 Tables (invoices, reports)
- 🖼 Images in PDF
- ✍ User input (forms → PDF)
- 📤 Share PDF
- 📚 Multiple pages

[…] is a simple, complete guide to build a PDF Viewer app in Flutter, with working source code. This is beginner-friendly and […]