Facebook Twitter Instagram
    DeepCrazyWorld
    Facebook Twitter Instagram Pinterest YouTube
    • FLUTTER
      • FLUTTER APP
        • QRCode
        • Quiz App
        • Chat GPT
        • PDF App
        • News App
        • Fitness App
        • Weather App
        • BMI Calculator
        • GAME APP
        • Ecommerce App
        • wallpaper App
        • Finance app
        • Chat App
        • Wallet App
        • Taxi App
        • Quran app
        • Music player app
      • FLUTTER UI
        • Splash Screen
        • Onboarding Screen
        • Login Screen
        • Card Design
        • Drawer
    • PROJECT
      • Android Projects
      • College Projects
      • FLUTTER APP
      • Project Ideas
      • PHP Projects
      • Python Projects
    • SOURCE CODE
    • ANDROID
      • ANDROID APP
      • GAME APP
      • ANDROID STUDIO
    • MCQ
      • AKTU MCQ
        • RPA MCQ
        • COA MCQ
        • HPC MCQ
        • SPM MCQ
        • Renewable Energy All MCQ
        • Data Compression MCQ
        • Data Structure MCQ
        • Digital Image Processing MCQ
        • Software Engineering MCQ
        • Machine Learning MCQ
        • Artificial Intelligence MCQ
      • D PHARMA MCQ
        • Pharmaceutics – I MCQ
        • Pharmacognosy MCQ
        • Pharmaceutical Chemistry MCQ
        • Biochemistry and Clinical Pathology MCQ
        • Human Anatomy and Physiology MCQ
        • Heath Education and Community Pharmacy MCQ
    • INTERVIEW QUESTIONS
      • Flutter Interview Questions
      • INTERVIEW QUESTIONS
      • Python Interview Questions
      • Coding ninjas solution
    • MORE
      • WORDPRESS
        • SEO
        • TOP 10 WORDPRESS THEME
      • PRODUCTIVITY
      • Program
      • QUOTES
    DeepCrazyWorld
    Home»FLUTTER APP»How to Make Image to Pdf Converter app in Flutter with Source Code
    FLUTTER APP

    How to Make Image to Pdf Converter app in Flutter with Source Code

    DeepikaBy DeepikaAugust 20, 2024Updated:March 29, 2025No Comments4 Mins Read

    Creating an image-to-PDF converter app in Flutter involves several steps. Here’s a step-by-step guide, along with the necessary code snippets, to help you build this app.

    Table of Contents

    Toggle
    • Step 1: Set Up Flutter Project
    • Step 2: Implement UI
    • Step 3: Handle Permissions (Android)
    • Step 4: Run the App
    • Step 5: Test the Output
    • Step 6: (Optional) Improve the App
    • Output
    • Related Articles

    Step 1: Set Up Flutter Project

    1. Create a new Flutter project:
       flutter create image_to_pdf
       cd image_to_pdf
    1. Add necessary dependencies in pubspec.yaml:
       dependencies:
         flutter:
           sdk: flutter
         image_picker: ^0.8.4+2
         pdf: ^3.6.1
         path_provider: ^2.0.2

    Run flutter pub get to install the dependencies.

    Step 2: Implement UI

    1. Create a simple UI in lib/main.dart:
       import 'dart:io';
    
       import 'package:flutter/material.dart';
       import 'package:image_picker/image_picker.dart';
       import 'package:pdf/widgets.dart' as pw;
       import 'package:path_provider/path_provider.dart';
       import 'package:permission_handler/permission_handler.dart';
    
       void main() {
         runApp(MyApp());
       }
    
       class MyApp extends StatelessWidget {
         @override
         Widget build(BuildContext context) {
           return MaterialApp(
             home: ImageToPdfConverter(),
           );
         }
       }
    
       class ImageToPdfConverter extends StatefulWidget {
         @override
         _ImageToPdfConverterState createState() => _ImageToPdfConverterState();
       }
    
       class _ImageToPdfConverterState extends State<ImageToPdfConverter> {
         final picker = ImagePicker();
         List<File> _images = [];
    
         Future<void> pickImage() async {
           final pickedFile = await picker.pickImage(source: ImageSource.gallery);
           if (pickedFile != null) {
             setState(() {
               _images.add(File(pickedFile.path));
             });
           }
         }
    
         Future<void> createPDF() async {
           final pdf = pw.Document();
           for (var img in _images) {
             final image = pw.MemoryImage(img.readAsBytesSync());
             pdf.addPage(pw.Page(
               build: (pw.Context context) {
                 return pw.Center(
                   child: pw.Image(image),
                 );
               },
             ));
           }
    
           final output = await getTemporaryDirectory();
           final file = File("${output.path}/example.pdf");
           await file.writeAsBytes(await pdf.save());
           print("PDF saved to ${file.path}");
         }
    
         @override
         Widget build(BuildContext context) {
           return Scaffold(
             appBar: AppBar(
               title: Text('Image to PDF Converter'),
             ),
             body: Center(
               child: Column(
                 mainAxisAlignment: MainAxisAlignment.center,
                 children: [
                   ElevatedButton(
                     onPressed: pickImage,
                     child: Text('Pick Image'),
                   ),
                   SizedBox(height: 20),
                   ElevatedButton(
                     onPressed: createPDF,
                     child: Text('Create PDF'),
                   ),
                 ],
               ),
             ),
           );
         }
       }

    Step 3: Handle Permissions (Android)

    1. Add permissions to AndroidManifest.xml:
       <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
       <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    1. Request permission using permission_handler:
      Add the permission handling code to the createPDF method:
       Future<void> createPDF() async {
         if (await Permission.storage.request().isGranted) {
           final pdf = pw.Document();
           for (var img in _images) {
             final image = pw.MemoryImage(img.readAsBytesSync());
             pdf.addPage(pw.Page(
               build: (pw.Context context) {
                 return pw.Center(
                   child: pw.Image(image),
                 );
               },
             ));
           }
    
           final output = await getTemporaryDirectory();
           final file = File("${output.path}/example.pdf");
           await file.writeAsBytes(await pdf.save());
           print("PDF saved to ${file.path}");
         }
       }

    Step 4: Run the App

    1. Run the app on an emulator or physical device:
       flutter run

    Step 5: Test the Output

    1. Pick an image and create a PDF:
    • Press the “Pick Image” button to select an image.
    • Press the “Create PDF” button to generate a PDF file from the selected image.
    1. Check the output:
    • The console will print the location of the generated PDF file.
    • You can open the PDF file using a file manager or PDF viewer.

    Step 6: (Optional) Improve the App

    • Add multiple image selection.
    • Enhance the UI for a better user experience.
    • Add options to save the PDF file to a specific location.
    • Handle edge cases, such as no image selected or permission denied.

    This basic app allows users to select an image from their device’s gallery, convert it into a PDF, and save it locally.

    Output

    Here’s the output image showing how the Flutter app might look on a mobile device. image to pdf converter app.

    Related Articles

    • How to make Ludo app in Flutter with Source Code Step by step
    • How to make PDF Reader app in Flutter with Source Code Step by step
    • How to make QR Scanner app in Flutter with Source Code Step by step
    • How to Make a ToDo App with Flutter with source Code StepWise in 2024
    • What is package in Flutter (Dart) with example in 2024
    • What is class in Flutter(Dart) with example step by step
    • Advantage of Flutter with examples in 2024
    • Top 15 Amazing Applications Built with Flutter Framework
    • Specialized PDF reader designed specifically for music sheets
    • Flutter File Integrity Checker app for checking integrity of a file
    • Christmas Quote Generator app built with flutter source code
    • Create fast food orders and bundle it up into a QR code with flutter
    • How to make custom BottomNavigationBar in flutter with source code

    Share. Facebook Twitter LinkedIn WhatsApp Telegram Pinterest Reddit Email
    Previous ArticleHow to make custom BottomNavigationBar in flutter with source code
    Next Article How to make review and rating ui with flutter stepwise

    Related Posts

    How to make Diary App using flutter stepwise using getx

    FLUTTER APP 4 Mins Read

    How to Create Music Player UI screen with fully functional in flutter

    FLUTTER APP 3 Mins Read

    How to make Heart rate measure app with Flutter stepwise

    FLUTTER APP 5 Mins Read

    How to make ChatGpt App in flutter with source code Stepwise

    Chat GPT 5 Mins Read

    Leave A Reply Cancel Reply

    Recent Posts
    • Implementing a Dynamic FAQ Screen UI in Flutter Using ExpansionTile March 29, 2025
    • Creating an Instruction UI Screen in Flutter Application March 29, 2025
    • Animated Backgrounds in Flutter: A Complete Guide March 15, 2025
    • How to make Diary App using flutter stepwise using getx August 31, 2024
    • How to Create Music Player UI screen with fully functional in flutter August 30, 2024
    • How to make ListView Builder Ui in flutter with Source Code August 29, 2024
    • Create a TabBar View in flutter with fully functional stepwise August 28, 2024
    • How to create TabBar view in flutter with source code step wise August 27, 2024
    • How to make Heart rate measure app with Flutter stepwise August 26, 2024
    • How to make ChatGpt App in flutter with source code Stepwise August 25, 2024
    Facebook Twitter Instagram Pinterest YouTube
    • About
    • Contact
    • Disclaimer
    • Privacy Policy
    Copyright by DeepCrazyWorld © 2025

    Type above and press Enter to search. Press Esc to cancel.