issue with arabic fonts

Hello,

I have problem when creat pdf with arabic letters

this is my configuration:

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)
);

5 Replies 1 reply marked as answer

CM Chinnu Muniyappan Syncfusion Team July 21, 2020 07:42 AM UTC

Hi Ahmed, 
 
Thank you for contacting Syncfusion support. 
 
We have created a sample to load the font file from the asset and drawn the Arabic text using the font data. Kindly try the following code example and sample in your side and let us know whether the issue is resolved at your end. 
 
  1. Import the following package in your dart file.
 
import 'package:flutter/services.dart'; 
 
  1. Add a method to read font data.
 
  Future<List<int>> _readFontData() async { 
    final ByteData bytes = await rootBundle.load('assets/fonts/arial.ttf'); 
    return bytes.buffer.asUint8List(bytes.offsetInBytes, bytes.lengthInBytes); 
  } 
 
  1. Draw text in PDF.
 
    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( 
            00, page.getClientSize().width, page.getClientSize().height), 
        format: PdfStringFormat( 
            textDirection: PdfTextDirection.rightToLeft, 
            alignment: PdfTextAlignment.right, 
            paragraphIndent: 35)); 
 
 
 
 
Regards, 
Chinnu M 


Marked as answer

AH ahmed August 18, 2020 11:17 AM UTC

It is working
thanks


is this free library



CM Chinnu Muniyappan Syncfusion Team August 19, 2020 06:26 AM UTC

Hi Ahmed, 
 
Yes, the services is available in the flutter framework (SDK), so it is the free library. And syncfusion_flutter_pdf is a commercial package. To use this package, you need to have either a Syncfusion Commercial License or Syncfusion Community license. For more details, please check the LICENSE file. 
 
Regards, 
Chinnu M 



YA Yacoub Almani March 24, 2023 11:28 PM UTC

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




SN Santhiya Narayanan Syncfusion Team March 25, 2023 07:06 AM UTC

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


Loader.
Up arrow icon