dart_pdf
dart_pdf copied to clipboard
Doesnt support RTL view
Describe the bug
I'm building a table and the table been viewed as LTR, not RTL means the first Column on the TABLE ROW is on the left side even with using the Directionality
with TextDirection.rtl
To Reproduce Code snippet to reproduce the behavior:
class MonthlyReportBloc extends Bloc<MonthlyReportEvent, MonthlyReportState> {
final TransactionsDao _transactionsDao;
StreamSubscription _transactionsSubscription;
MonthlyReportBloc(this._transactionsDao) : super(MonthlyReportInitial());
@override
Future<void> close() async {
await _transactionsSubscription?.cancel();
return super.close();
}
@override
Stream<MonthlyReportState> mapEventToState(
MonthlyReportEvent event,
) async* {
if ( event is ExportReport ) {
await _transactionsSubscription?.cancel();
_transactionsSubscription = _transactionsDao.watchAllTransactions().listen((List<TransactionWithCategory> transactions) async {
final Document pdf = Document();
final font = await rootBundle.load("assets/fonts/Cairo/Cairo-Regular.ttf");
final ttf = Font.ttf(
font
);
pdf.addPage(
Page(
textDirection: TextDirection.rtl,
// clip: true,
theme: ThemeData.withFont(
base: ttf,
),
pageFormat: PdfPageFormat.a4,
build: (context) {
return Directionality(
textDirection: TextDirection.rtl,
child: Table(
border: TableBorder.all(
width: 1
),
children: [
TableRow(
children: [
Container(
child: Text('التاريح')
),
Container(
child: Text('القسم')
),
Container(
child: Text('المبلغ')
),
Container(
child: Text('المتبقي بعد')
),
]
),
]
)
);
}
)
);
try {
final String dir = (await getApplicationDocumentsDirectory()).path;
final String path = '$dir/report.pdf';
final File file = File(path);
await file.writeAsBytes(await pdf.save());
await OpenFile.open(path);
} catch (e) {
throw e;
}
});
}
}
}
Expected behavior The Table Cols start from RTL.
Screenshots
I know you may not understand Arabic so let me explain the issue below, the order of cols is in the opposite order ( because it showing wrong direction even with using Directionality
with TextDirection.rtl
)
Flutter Doctor
eshams-MacBook-Pro:home_budget esham$ flutter doctor -v
[✓] Flutter (Channel stable, 1.22.5, on macOS 11.4 20F71 darwin-x64, locale en-EG)
• Flutter version 1.22.5 at /Users/esham/Development/flutter
• Framework revision 7891006299 (7 months ago), 2020-12-10 11:54:40 -0800
• Engine revision ae90085a84
• Dart version 2.10.4
[!] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
• Android SDK at /Users/esham/Library/Android/sdk
• Platform android-30, build-tools 29.0.2
• ANDROID_HOME = /Users/esham/Library/Android/sdk
• ANDROID_SDK_ROOT = /Users/esham/Library/Android/sdk
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses
[✓] Xcode - develop for iOS and macOS (Xcode 12.5)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 12.5, Build version 12E262
• CocoaPods version 1.10.1
[✓] Android Studio (version 3.5)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 39.0.3
• Dart plugin version 191.8423
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
[✓] VS Code (version 1.57.1)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.24.0
[✓] Connected device (1 available)
• Redmi Note 8 Pro (mobile) • hev4t4bqo7hyvsnf • android-arm64 • Android 10 (API 29)
! Doctor found issues in 1 category.
eshams-MacBook-Pro:home_budget esham$
Desktop (please complete the following information):
- [ ] iOS
- [x] Android
- [ ] Browser
- [ ] Windows
- [ ] Linux
Smartphone (please complete the following information):
- Device: Xiaomi note 8 pro
- OS: Android 10
- Plugin Version
pdf: ^2.1.0
Yes, RTL is not implemented.
Yes, RTL is not implemented.
Ok is there a way to even center the text on each column or make to the right even better?!
Yes, use Align(child:Text())
Yes, use Align(child:Text())
Thanks that's worked great, another question if you don't mind! what font do you support in Arabic or you have tested already, as I tried multiple fonts and some characters are missing in all of them?!
I don't read/write Arabic. A contributor implemented the text shaper. So I don't know.
The PR fixes this issue #1147
This will help https://www.youtube.com/watch?v=LLBoRBAQIw0
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days
Closing this stale issue because it has no activity.