DEV Community

AR Rahman
AR Rahman

Posted on

How to Create a PDF in Any Language with Flutter

pdf_maker is a powerful Flutter plugin that enables developers to design and generate high-quality PDF documents with complete control over layout, fonts, and language support. Whether you are building invoices, certificates, reports, or multilingual publications, pdf_maker ensures accurate rendering without breaking fonts or compromising quality.


Key Benefits

  • Any Language, Any Font – Full Unicode support ensures proper rendering for all scripts, including Arabic, Bengali, Chinese, Japanese, and more.
  • Design Flexibility – Build fully customized page layouts with Flutter widgets.
  • High-Quality Output – Fonts and images remain sharp and accurate in the final PDF.
  • Multi-Page Support – Easily combine multiple pages into a single document.
  • Real-Time Preview – Adjust layouts and see changes immediately during development.
  • Optimized Performance – Lightweight and fast with minimal configuration required.

Installation

Add pdf_maker to your pubspec.yaml:

dependencies:
  pdf_maker: ^1.1.0
Enter fullscreen mode Exit fullscreen mode

Then run:

flutter pub get
Enter fullscreen mode Exit fullscreen mode

Quick Start Guide

1. Create a Custom Page

Extend the BlankPage class to define your page layout using Flutter widgets.

import 'package:flutter/material.dart';
import 'package:pdf_maker/pdf_maker.dart';

class TestPage extends BlankPage {
  const TestPage({super.key});

  @override
  Widget createPageContent(BuildContext context) {
    return const Center(
      child: Text(
        'السلام عليكم', // Example: Arabic text
        style: TextStyle(fontSize: 28),
      ),
    );
  }
}
Enter fullscreen mode Exit fullscreen mode

2. Generate a Single-Page PDF

Use the static createPDF method to quickly generate and save a PDF.

ElevatedButton(
  onPressed: () async {
    final pdfFile = await BlankPage.createPDF(
      const TestPage(),
      setup: PageSetup(context: context),
    );
    saveAndOpen(pdfFile); // Implement your own file saving and opening method
  },
  child: const Text("Create PDF"),
);
Enter fullscreen mode Exit fullscreen mode

3. Generate a Multi-Page PDF

const pages = [Page1(), Page2(), Page3()];

final setup = PageSetup(
  context: context,
  quality: 4.0,
  scale: 1.0,
  pageFormat: PageFormat.a4,
  margins: 40,
);

ElevatedButton(
  onPressed: () async {
    final maker = PDFMaker();
    final pdfFile = await maker.createMultiPagePDF(pages, setup: setup);
    saveAndOpen(pdfFile);
  },
  child: const Text("Create Multi-Page PDF"),
);
Enter fullscreen mode Exit fullscreen mode

4. One-Line PDF Generation

For cleaner and more concise PDF creation:

// Single Page
final pdfFile = await const TestPage().toPDF(
  setup: PageSetup(context: context),
);

// Multiple Pages
const pages = [Page1(), Page2(), Page3()];
final multiPagePdf = await pages.toPDF();
Enter fullscreen mode Exit fullscreen mode

Ideal Use Cases

  • Multilingual invoices, reports, and certificates
  • Books, magazines, or brochures in any language
  • Marketing materials with custom branding
  • Print-ready documents with precise layouts
  • Applications that require dynamic PDF generation with complex typography

Why Choose pdf_maker

Unlike many other PDF generation tools, pdf_maker preserves the exact look of your Flutter UI while supporting any language or font. It avoids rasterization, ensuring that text remains selectable, fonts render correctly, and images stay crisp.

pdf in flutter

Top comments (0)