DEV Community

Praise Akinsola
Praise Akinsola

Posted on

How To Convert an Image into a PDF in Flutter (Dart)

Converting images to PDFs in Flutter is straightforward with the image_to_pdf_converter package.

Installation

flutter pub add image_to_pdf_converter
Enter fullscreen mode Exit fullscreen mode

Import the Package

import 'package:image_to_pdf_converter/image_to_pdf_converter.dart';
import 'dart:io';
Enter fullscreen mode Exit fullscreen mode

Usage

// The first image in the list will be page 1 and so on
final List<File> imageFiles = [
  File('/path/to/image1.jpg'),
  File('/path/to/image2.jpg'),
];

// Generate the PDF file
final File pdfFile = await ImageToPdf.imageList(listOfFiles: imageFiles);
Enter fullscreen mode Exit fullscreen mode

That's it. You can now save, share, or upload the PDF file as needed.

Top comments (0)