DavBfr / dart_pdf

Pdf creation module for dart/flutter
https://pub.dev/packages/pdf
Apache License 2.0
1.41k stars 632 forks source link

Trying to create a pdf in different languages?? #111

Closed Renkon117 closed 5 years ago

Renkon117 commented 5 years ago

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!!!!!!!!!!

Renkon117 commented 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????

Renkon117 commented 5 years ago

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

Niushimeng commented 5 years ago

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.

Renkon117 commented 5 years ago

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.

DavBfr commented 5 years ago

Using flutter, you can get the font from an asset. with something like: await rootBundle.load('file.ttf')

Renkon117 commented 5 years ago

It works now following your instruction!!!

Thanks a lot!!!

LSFMint commented 4 years ago

Hi guys,

anyway to allow (Chinese Text + English) font used at the same time for creating PDF file?

DavBfr commented 4 years ago

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!',
      ),
    ],
  ),
)
Screen Shot 2020-05-12 at 08 30 56
LSFMint commented 4 years ago

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?

DavBfr commented 4 years ago

You need to include one or many fonts that supports all your users, and somehow detect the language to use the right font.

Ahmedmedhat187 commented 4 years ago

Hello, I have problem with arabic letter,

mostafa5731 commented 3 years ago

Look at this link https://stackoverflow.com/a/66951313/10148146

RothaSoeurn commented 8 months ago

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

benchantha commented 5 months ago

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

benchantha commented 5 months ago

but my problem is that when print to pdf it show​ . it mean as revert text

អចេ អចេ ខេ អុីនធឺណេសិនណល

DyDev-1 commented 4 months ago

but my problem is that when print to pdf it show​ . it mean as revert text

អចេ អចេ ខេ អុីនធឺណេសិនណល

change font use Khmer batambang

RothaSoeurn commented 3 months ago

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 photo_2024-08-06_11-40-06 photo_2024-08-06_11-40-06

RothaSoeurn commented 3 months ago

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

DyDev-1 commented 3 months ago

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.

benchantha commented 3 months ago

prinT() async { final htmlContent = '''

Heading Example

  <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

benchantha commented 3 months ago

Screenshot (1280)

DyDev-1 commented 3 months ago

Screenshot (1280)

I also change to htmlpdf

DyDev-1 commented 3 months ago

html_to_pdf 0.8.1