bangla_pdf 1.0.2 copy "bangla_pdf: ^1.0.2" to clipboard
bangla_pdf: ^1.0.2 copied to clipboard

A package to fix broken font issues in PDFs for Bangla text.

Bangla PDF 🔧 #

Stand With Palestine

Bangla PDF is a Flutter package designed to fix broken Bangla fonts in PDFs, ensuring accurate rendering of Bangla characters with 22+ high-quality custom fonts.

A lightweight, focused solution for Bangla font issues—nothing more, nothing less.


Features #

  • 22+ Bangla fonts for effortless customization of PDF text.
  • Automatically rearranges complex Bangla characters for correct display.
  • Seamless integration with Flutter PDF generation workflows.
  • Ready-to-use Bangla widgets: text, headers, paragraphs, tables, and bullet lists.

Installation #

Add to your pubspec.yaml:

dependencies:
  bangla_pdf: ^1.0.2

Install packages:

flutter pub get

Usage ✨ #

[Note] BanglaFontType: 🎨 The BanglaFontType class is a centralized enum of 22+ Bangla fonts for PDF generation. It simplifies working with Bangla text in Flutter by providing ready-to-use pw.TextStyle and pw.Text widgets, making font assignment seamless and reducing boilerplate.


Step 1: Initialize Fonts #

Before using any widgets, initialize the font manager:

await BanglaFontManager().initialize();

This ensures all fonts are loaded and ready for use.


Step 2: Fix Bangla Text in PDFs #

Use the .fix extension to automatically correct broken Bangla text:

BanglaText(
  'বাংলা সাধারণ টেক্সট',
  fontType: BanglaFontType.kalpurush,
  fontSize: 20,
),
pw.SizedBox(height: 10),
pw.Text(
  'বেঁচে থাকার মত আনন্দ আর কিছুই নেই।'.fix,
  style: BanglaFontType.july.ts(
    fontSize: 24,
    fontWeight: pw.FontWeight.bold,
    color: PdfColors.red,
  ),
),

Most widgets apply .fix internally, so manual usage is optional.


Example: Generate a PDF in Flutter #

import 'package:bangla_pdf/bangla_pdf.dart';
import 'package:pdf/widgets.dart' as pw;
import 'package:path_provider/path_provider.dart';
import 'package:open_file/open_file.dart';
import 'dart:io';

Future<void> generateAndOpenPdf() async {
  await BanglaFontManager().initialize();

  final pdf = pw.Document();

  pdf.addPage(
    pw.Page(
      build: (context) => pw.Column(
        crossAxisAlignment: pw.CrossAxisAlignment.start,
        children: [
          BanglaText(
            'বাংলা সাধারণ টেক্সট',
            fontType: BanglaFontType.kalpurush,
            fontSize: 20,
          ),
          pw.SizedBox(height: 10),
          pw.Text(
            'বেঁচে থাকার মত আনন্দ আর কিছুই নেই।'.fix,
            style: BanglaFontType.july.ts(
              fontSize: 24,
              fontWeight: pw.FontWeight.bold,
              color: PdfColors.red,
            ),
          ),
        ],
      ),
    ),
  );

  final dir = await getApplicationDocumentsDirectory();
  final file = File("${dir.path}/example.pdf");
  await file.writeAsBytes(await pdf.save());
  await OpenFile.open(file.path);
}

Step 3: Use PDF Fixer Widgets #

Bangla PDF provides ready-to-use widgets that automatically handle font corrections:

These widgets integrate seamlessly with the pdf package, allowing you to focus on content while the package handles Bangla text corrections.


1. BanglaAutoText #

Automatically detects and renders mixed Bangla and English text with appropriate fonts:

BanglaAutoText(
  'আমার নাম Zaman Sheikh এবং আমি ঢাকা থেকে এসেছি।',
  fontSize: 16,
  banglaFontType: BanglaFontType.kalpurush,
  color: PdfColors.black,
);

With custom styling:

BanglaAutoText(
  'দাম: ৳ 500 Price: $50',
  fontSize: 14,
  banglaFontType: BanglaFontType.july,
  fontWeight: pw.FontWeight.bold,
  color: PdfColors.blue,
);

2. BanglaText #

BanglaText(
  'বাংলা সাধারণ টেক্সট',
  fontType: BanglaFontType.kalpurush,
  fontSize: 18,
);

3. BanglaRichText #

BanglaRichText(
  spans: [
    BanglaTextSpan('বাংলা বোল্ড ', fontWeight: pw.FontWeight.bold),
    BanglaTextSpan('এবং ইটালিক', fontType: BanglaFontType.julyItalic),
  ],
);

4. BanglaHeader #

BanglaHeader('বাংলা শিরোনাম');

5. BanglaParagraph #

BanglaParagraph('বাংলা অনুচ্ছেদ এখানে লেখা হবে।');

6. BanglaBulletList #

BanglaBulletList(
  items: ['প্রথম আইটেম', 'দ্বিতীয় আইটেম', 'তৃতীয় আইটেম'],
  bullet: '>',
);

7. BanglaTable #

Now supports mixed Bangla and English in cells:

BanglaTable(
  data: [
    ['নাম (Name)', 'বয়স (Age)', 'শহর (City)'],
    ['আহমেদ Ahmed', '२५ (25)', 'ঢাকা Dhaka'],
    ['সারা Sara', '३० (30)', 'চট্টগ্রাম Chittagong'],
    ['রাহুল Rahul', '०२८ (28)', 'সিলেট Sylhet'],
  ],
  fontType: BanglaFontType.tomalicca,
  fontSize: 14,
  fontWeight: pw.FontWeight.normal,
);

Step 4: TextStyle & Widget Shortcuts #

// TextStyle shortcut
pw.Text(
  'বাংলা শিরোনাম'.fix,
  style: BanglaFontType.july.ts(
    fontSize: 24,
    fontWeight: pw.FontWeight.bold,
    color: PdfColors.red,
  ),
);

// Text widget shortcut
BanglaFontType.kalpurush.text(
  'বাংলা লেখা',
  fontSize: 18,
  color: PdfColors.black,
);

Demo Preview 📥 #

View a sample PDF output:

Click here to check the demo PDF


Contributing 🚀 #

Contributions are welcome! Whether you want to:

  • Report a bug
  • Suggest a feature
  • Improve widgets or documentation

Fork the repository, make changes, and submit a Pull Request. Together, we can enhance Bangla PDF! 💡


License #

This project is licensed under the MIT License. Read the full license here.


Author #

Maintained by Zaman Sheikh Contact: [email protected]


Special Thanks 🙏✨ #

A big thank you to all Bangla font creators and contributors. Your efforts make high-quality, beautiful Bangla PDFs possible. 💖


⭐ If you find Bangla PDF helpful, please star the repository!

9
likes
0
points
34
downloads

Publisher

verified publisherzamansheikh.com

Weekly Downloads

A package to fix broken font issues in PDFs for Bangla text.

Repository (GitHub)
View/report issues

Topics

#flutter #pdf #bangla #fonts #pdf-generation

Documentation

Documentation

License

unknown (license)

Dependencies

flutter, pdf, plugin_platform_interface

More

Packages that depend on bangla_pdf