Closed Renkon117 closed 5 years ago
I read the document and now trying to use ttf file from asset/fonts/ folder. But, it's not working. any suggestion????
I have trouble on reading ttf from asset folder. I was following instructions on document. please help To use a TrueType font:
final Uint8List fontData = File('open-sans.ttf').readAsBytesSync(); final ttf = Font.ttf(fontData.buffer.asByteData());
pdf.addPage(Page( pageFormat: PdfPageFormat.a4, build: (Context context) { return Center( child: Text('Hello World', style: TextStyle(font: ttf, fontSize: 40)), ); // Center })); // Page
I have the same trouble as you.I use a Chinese font.It used to work, but now, There was a mistake when I upgraded.But I've always used TTF.
Can not decode the string to Latin1. This font does not support Unicode characters. If you want to use strings other than Latin strings, use a TrueType (TTF) font instead.
Ya, I had the exact same error when I tried it. We ended up trying to save the TTF font file (of the language) into temporary storage in app. We can now use whatever TTF font we want. However, I would like to know the accurate way instead of using temporary storage.
Using flutter, you can get the font from an asset.
with something like: await rootBundle.load('file.ttf')
It works now following your instruction!!!
Thanks a lot!!!
Hi guys,
anyway to allow (Chinese Text + English) font used at the same time for creating PDF file?
if you need to print Chinese and English in the same paragraph, you can use RichText with specific fonts in spans.
RichText(
text: TextSpan(
text: 'Hello ',
style: TextStyle(
font: ttf,
fontSize: 20,
),
children: <InlineSpan>[
TextSpan(
text: '中文',
style: TextStyle(font: asian),
),
TextSpan(
text: ' world!',
),
],
),
)
Thanks @DavBfr,
If the text is input by user with any language words (e.g.: Chinese, English and Thai.) , can we support in this case? Or is it possible to implement multiple font family in the Theme?
You need to include one or many fonts that supports all your users, and somehow detect the language to use the right font.
Hello, I have problem with arabic letter,
Look at this link https://stackoverflow.com/a/66951313/10148146
hello can u help me if me usering font khmer it not support font khmer in pdf . this error message -> Unable to find a font to draw "់" (U+17cb) try to provide a TextStyle.fontFallback
final khmerFont = pw.Font.ttf(await rootBundle.load( 'assets/fonts/KhmerOs/KhmerOS.ttf'));
hello can u help me if me usering font khmer it not support font khmer in pdf . this error message -> Unable to find a font to draw "់" (U+17cb) try to provide a TextStyle.fontFallback
final khmerFont = pw.Font.ttf(await rootBundle.load( 'assets/fonts/KhmerOs/KhmerOS.ttf'));
use can use this
final sss = await fontFromAssetBundle('images/fonts/KhmerOS.ttf');
pw.Text( 'អេច អេច ខេ អុីនធឺណេសិនណល', style: pw.TextStyle(font: sss) ),
but my problem is that when print to pdf it show . it mean as revert text
អចេ អចេ ខេ អុីនធឺណេសិនណល
but my problem is that when print to pdf it show . it mean as revert text
អចេ អចេ ខេ អុីនធឺណេសិនណល
change font use Khmer batambang
but my problem is that when print to pdf it show . it mean as revert text អចេ អចេ ខេ អុីនធឺណេសិនណល
change font use Khmer batambang
But is show but
but my problem is that when print to pdf it show . it mean as revert text អចេ អចេ ខេ អុីនធឺណេសិនណល
change font use Khmer batambang
Can you help me
but my problem is that when print to pdf it show . it mean as revert text អចេ អចេ ខេ អុីនធឺណេសិនណល
change font use Khmer batambang
Can you help me
You can use
final Uint8List fontData = File('open-sans.ttf').readAsBytesSync(); final ttf = Font.ttf(fontData.buffer.asByteData());
but you can try another plugin like htmlpdf flutter.
prinT() async { final htmlContent = '''
<p>សួស្តី សុខសប្បាយជាទេ?</p>
<img src="image.jpg" alt="Example Image" />
<blockquote>This is a quote.</blockquote>
<ul>
<li>First item</li>
<li>Second item</li>
<li>Third item</li>
</ul>
''';
final ByteData data = await rootBundle.load('images/fonts/KhmerOS.ttf');
final Uint8List fontData = data.buffer.asUint8List();
final ttf = Font.ttf(fontData.buffer.asByteData());
final path = await _localPath;
Directory generalDownloadDir = Directory('/storage/emulated/0/Download');
final pathQ = generalDownloadDir.path;
var file = File('$pathQ/example.pdf');
final newpdf = Document();
List<Widget> widgets = await HTMLToPdf().convert(htmlContent, defaultFont: ttf );
newpdf.addPage(MultiPage(
maxPages: 200,
build: (context) {
return widgets;
}));
await file.writeAsBytes(await newpdf.save()).then((value) {
print('sss $value');
});
}
but it 's not work b
I also change to htmlpdf
html_to_pdf 0.8.1
Hello, I enjoyed using this package so far. It's been working perfect. I really appreciate your work so much.
And I was just wondering if there is any way I can create a new pdf file in another language. I typed some japanese words in string. and it throw me errors regarding unicode or what ever. If you think of any solution or suggestion for this problem, I will be very appreciate that.
Again, Thank you for your work!!!!!!!!!!