Converting Flutter Screens to Shareable PDFs: A Complete Guide

Learn how to convert a Flutter screen or widget into a shareable PDF and seamlessly share it with other apps in just a few steps.

Author

Priyanka Singla
Priyanka SinglaSoftware Engineer - II

Date

Sep 25, 2024

Table of Contents

Sharing PDFs is a crucial feature for many modern mobile applications. Whether you're generating invoices, reports, or any other documents, enabling PDF generation and sharing is a vital part of creating interactive and feature-rich applications.

In this guide, we'll walk through how to integrate PDF generation and sharing functionality in your Flutter app using the pdf, path_provider, and share_plus packages. By the end of this article, you can generate, display, and share a PDF file right from your Flutter application.

Why PDFs?

PDFs are universally accepted and accessible on any device, making them an ideal format for documents like receipts, reports, or contracts. Integrating PDF generation into your Flutter app allows you to deliver this functionality directly to your users, keeping them engaged and providing a convenient way to export information from your app.

Key Features of PDF Generation and Sharing

  • Cross-Platform Support: Just like OneSignal, the libraries we’ll use support both Android and iOS, enabling you to use a single solution for both platforms.
  • Simple Integration: Using the pdf and share_plus packages, Flutter developers can easily implement PDF generation and sharing functionality with minimal code.
  • Rich PDF Content: Create PDFs that contain rich content like text, tables, and even images, making your application more interactive and engaging.

Steps to Implement PDF Generation and Sharing in Flutter

1. Install the Required Plugins

To get started, you need to add the necessary dependencies to your pubspec.yaml file. These plugins provide the foundation for PDF creation, accessing the file system, and sharing the generated files.

  • pdf: This package provides tools for creating PDF files.
  • path_provider: This plugin allows us to access directories on the device's file system.
  • share_plus: This package enables the sharing of files with other apps, making it easy to send PDFs.

After adding the dependencies, run flutter pub get to install them.


2. Basic Setup for PDF Generation and Sharing

In this step, we’ll write a Flutter function to generate a basic PDF document containing some sample content, followed by sharing the generated PDF using the share_plus plugin.

Step 1: Generating a PDF

First, let's write the method to generate a simple PDF. In this example, we'll create a PDF with text content such as an invoice or receipt.

Here’s what’s happening:

  • PDF Creation: We use the pdf package to create a document (pw.Document()) and add content (text, in this case) to it.
  • File Storage: The generated PDF is stored in the temporary directory of the device using the path_provider plugin.

Step 2: Sharing the PDF

Once the PDF is generated, you can use the share_plus plugin to share the file with other applications, such as email or messaging apps. Here’s how to implement the sharing functionality:

In this method, the file is retrieved from the temporary directory, and the shareXFiles method of the share_plus plugin is used to share it.

3. Complete Integration: Generate and Share PDFs

With both PDF generation and sharing functions in place, let’s integrate everything into a simple Flutter application. Below is the complete code that handles generating and sharing a sample PDF:

Complete Code Example

main.dart

bill_page.dart

  • PDF Generation: When the button is pressed, the app generates a PDF with sample content and saves it to the temporary directory.

PDF Sharing: Once the PDF is saved, the app allows users to share it with other apps (email, messaging, etc.) using the device’s native share sheet.

For a hands-on experience and to better understand the workflow, dive into the code. Feel free to explore the implementation via this GitHub repository.

Conclusion

Incorporating PDF generation and sharing into your Flutter application adds a valuable feature, allowing users to export and share documents seamlessly. With just a few lines of code, you can provide this functionality across both iOS and Android, improving the user experience and adding professional document handling to your app.

By using the pdf, path_provider, and share_plus packages, you can easily implement this functionality and offer a complete solution for PDF generation and sharing in your Flutter projects.

SHARE ON

Related Articles.

More from the engineering frontline.

Dive deep into our research and insights on design, development, and the impact of various trends to businesses.

How We Built an AI System That Automates Senior Solution Architect Workflows
Article

Apr 6, 2026

How We Built an AI System That Automates Senior Solution Architect Workflows

Discover how we built a 4-agent AI co-pilot that converts complex RFPs into draft technical proposals in 15 minutes — with built-in conflict detection, assumption surfacing, and confidence scoring.

AI Code Healer for Fixing Broken CI/CD Builds Fast
Article

Apr 6, 2026

AI Code Healer for Fixing Broken CI/CD Builds Fast

A deep dive into how GeekyAnts built an AI-powered Code Healer that analyzes CI/CD failures, summarizes logs, and generates code-level fixes to keep development moving.

A Real-Time AI Fraud Decision Engine Under 50ms
Article

Apr 2, 2026

A Real-Time AI Fraud Decision Engine Under 50ms

A deep dive into how GeekyAnts built a real-time AI fraud detection system that evaluates transactions in milliseconds using a hybrid multi-agent approach.

Building an Autonomous Multi-Agent Fraud Detection System in Under 200ms
Article

Apr 1, 2026

Building an Autonomous Multi-Agent Fraud Detection System in Under 200ms

GeekyAnts built a 5-agent fraud detection pipeline that makes decisions in under 200ms — 15x cheaper than single-model systems, with full explainability built in.

Building a Self-Healing CI/CD System with an AI Agent
Article

Mar 31, 2026

Building a Self-Healing CI/CD System with an AI Agent

When code breaks a pipeline, developers have to stop working and figure out why. This blog shows how an AI agent reads the error, finds the fix, and submits it for review all on its own.

Maestro Automation Framework — Advanced to Expert
Article

Mar 26, 2026

Maestro Automation Framework — Advanced to Expert

Master Maestro at scale. Learn architecture, reusable flows, CI/CD optimization, and how to eliminate flakiness in production-grade mobile automation.Master Maestro at scale. Learn architecture, reusable flows, CI/CD optimization, and how to eliminate flakiness in production-grade mobile automation.

Scroll for more
View all articles