fonts:
- family: Arial
fonts:
- asset: assets/fonts/Arial.ttf
PdfDocument document = PdfDocument();
document.pageSettings.size = PdfPageSize.a4;
PdfPage page = document.pages.add();
PdfGraphics graphics = page.graphics;PdfFont font = PdfTrueTypeFont(File('assets/fonts/Arial.ttf').readAsBytesSync(), 12);
graphics.drawString(
"السلام عليكم", font,
brush: PdfBrushes.black,
bounds: Rect.fromLTWH(0, 0, page.getClientSize().width, page.getClientSize().height),
format: PdfStringFormat(textDirection: PdfTextDirection.rightToLeft, alignment: PdfTextAlignment.right, paragraphIndent: 35)
);
|
import 'package:flutter/services.dart'; |
|
Future<List<int>> _readFontData() async {
final ByteData bytes = await rootBundle.load('assets/fonts/arial.ttf');
return bytes.buffer.asUint8List(bytes.offsetInBytes, bytes.lengthInBytes);
} |
|
PdfDocument document = PdfDocument();
document.pageSettings.size = PdfPageSize.a4;
PdfPage page = document.pages.add();
PdfGraphics graphics = page.graphics;
PdfFont font = PdfTrueTypeFont(await _readFontData(), 12);
graphics.drawString("السلام عليكم", font,
brush: PdfBrushes.black,
bounds: Rect.fromLTWH(
0, 0, page.getClientSize().width, page.getClientSize().height),
format: PdfStringFormat(
textDirection: PdfTextDirection.rightToLeft,
alignment: PdfTextAlignment.right,
paragraphIndent: 35));
|
I need to create a PDF file with Arabic Language.
I was trying to use your code as above but always I receive the following error
Unsupported operation: _Namespace.
I'm using Flutter language for website.
Even to get the google font code also I receive error as I think this code for mobile application.
This command getApplicationSupportDirectory() for mobile application and not web
Future<PdfFont> getGoogleFont(TextStyle style) async {
//Get the external storage directory
// Directory directory = await getTemporaryDirectory();
Directory directory = await getApplicationSupportDirectory();
//Create an empty file to write the font data
File file = File('${directory.path}/${style.fontFamily}.ttf');
List<int>? fontBytes;
//Check if entity with the path exists
if (file.existsSync()) {
fontBytes = await file.readAsBytes();
}
if (fontBytes != null && fontBytes.isNotEmpty) {
//Return the google font
return PdfTrueTypeFont(fontBytes, 12);
} else {
//Return the default font
return PdfStandardFont(PdfFontFamily.helvetica, 12);
}
}
Thanking you and looking to receive your earliest reply.
Best Regards,
Yacoub Almani
Currently, we do not have support to draw complex script language texts such as Marathi, Tamil, Hindi, and more. We have logged the feature for “Complex script text drawing support in Flutter PDF” and added it to our feature request list. We will implement this feature in any of our upcoming releases.
You can track the feature status using the feedback from https://www.syncfusion.com/feedback/20541/complex-script-text-drawing-support-in-flutter-pdf