tamil_pdf_shaper 1.0.0
tamil_pdf_shaper: ^1.0.0 copied to clipboard
A production-grade engine to render Tamil Unicode text correctly in Flutter PDF workflows. Includes embedded glyph mapping and font management.
Tamil PDF Shaper
A production-grade Flutter engine for rendering Tamil Unicode text correctly in PDF documents.
வணக்கம் (Hello)
Rendering Indic languages like Tamil in standard PDF generators (like package:pdf) is historically difficult. Standard Unicode strings often break because PDF renderers lack the complex text shaping engines (HarfBuzz, etc.) required to handle character reordering (e.g., placing the Kombu 'ெ' before the consonant).
Tamil PDF Shaper solves this by:
Bundling a compatible font (Anand MuktaMalar) optimized for this purpose.
Providing a shaping engine that maps Unicode characters to the specific glyphs and byte-orders required by the font.
Features
🚀 Zero Configuration: Font is included and auto-loaded.
⚡ High Performance: Optimized StringBuffer-based conversion.
🛡️ Safe: Gracefully handles mixed English/Tamil text.
💙 Flutter Native: Built for the Flutter ecosystem.
Installation
Add to pubspec.yaml:
dependencies: tamil_pdf_shaper: ^1.0.0
Usage
- Load the Font
Load the font once (usually inside your PDF generation function).
import 'package:tamil_pdf_shaper/tamil_pdf_shaper.dart';
final tamilFont = await TamilPdfFont.load();
- Apply to Text
Use the .toTamilPdf extension on any string.
pw.Text( "தமிழ் வாழ்க".toTamilPdf, // Automatically handles glyph reordering style: pw.TextStyle(font: tamilFont, fontSize: 20), );
Full Example
Future
pdf.addPage(pw.Page( theme: pw.ThemeData.withFont(base: font), build: (ctx) => pw.Column( children: [ pw.Text("பெயர்: ஆனந்த்".toTamilPdf), pw.Text("தேதி: 01/01/2024".toTamilPdf), ], ), ));
return pdf.save(); }
How it Works
The package uses a custom mapping engine to translate Unicode grapheme clusters into legacy-style glyph sequences.
For example, the character கொ (Ko) consists of க் + ஒ.
Standard PDF Rendering: Renders க followed by ொ (Incorrect).
Tamil PDF Shaper: Converts it to ெ (The loop) + க (The base) + ா (The leg), ensuring it looks correct visually.
Credits
Font: Anand MuktaMalar (Open Source).
Developed for the global Tamil developer community.
Made with ❤️ for Tamil