alihassan143 / htmltopdfwidgets

Html To Pdf
https://pub.dev/packages/htmltopdfwidgets
Apache License 2.0
12 stars 18 forks source link

font isn't work? #10

Closed xiaodusx1 closed 1 year ago

xiaodusx1 commented 1 year ago

bug:Helvetica-Bold has no Unicode support see https://github.com/DavBfr/dart_pdf/wiki/Fonts-Management. but use pdf can work fine: final Uint8List fontData = File('assets/kaiti.ttf').readAsBytesSync();//await rootBundle.load("assets/kaiti.ttf"); final ttf = pw.Font.ttf(fontData.buffer.asByteData()); final pdf = pw.Document(); var filePath = 'assets/example.pdf'; var file = File(filePath); pdf.addPage(pw.Page( pageFormat: PdfPageFormat.a4, build: (pw.Context context) { return pw.Center( child: pw.Text('''

welcome to beijing

亚硝酸盐

''', style: pw.TextStyle(font: ttf, fontSize: 40)), ); // Center })); // Page await file.writeAsBytes(await pdf.save());

use htmltopdfwidgets: var filePath = 'assets/exampleH.pdf'; var file = File(filePath); final newpdf = Document(); final html = '''

welcome to beijing

亚硝酸盐

'''; final Uint8List fontData = File('assets/kaiti.ttf').readAsBytesSync();//await rootBundle.load("assets/kaiti.ttf"); final ttf = pw.Font.ttf(fontData.buffer.asByteData()); var widgets = await HTMLToPdf().convert(html,defaultFont: ttf); newpdf.addPage(MultiPage( maxPages: 200, build: (context) { return widgets; })); await file.writeAsBytes(await newpdf.save());

isn't work:Helvetica-Bold has no Unicode support see https://github.com/DavBfr/dart_pdf/wiki/Fonts-Management

alihassan143 commented 1 year ago

@xiaodusx1 you need to add custom fonts in the method currently this package didn't suppot chinese japnese and korean language font by default but you can add your custom font in the app just provide fallback font it will works perfectly

xiaodusx1 commented 1 year ago

@xiaodusx1 you need to add custom fonts in the method currently this package didn't suppot chinese japnese and korean language font by default but you can add your custom font in the app just provide fallback font it will works perfectly

ok,It work.