Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cyrillic Characters are not displayed #1806

Open
ismail-go opened this issue Jan 13, 2025 · 2 comments
Open

Cyrillic Characters are not displayed #1806

ismail-go opened this issue Jan 13, 2025 · 2 comments
Labels
bug Something isn't working needs triage

Comments

@ismail-go
Copy link

ismail-go commented Jan 13, 2025

Cyrillic characters are not displayed on the pdf file. The characters are not supported.

Future<pw.Document> saveTextAsPdf(List items, String title) async {
final pdf = pw.Document(title: title);
try {
// Load the custom font
final fontData = await rootBundle.load(Assets.fonts.transcription.poppinsRegular);
final font = pw.Font.ttf(fontData.buffer.asByteData());
pdf.addPage(
pw.MultiPage(
pageFormat: PdfPageFormat.a4,
maxPages: 1000,
margin: pw.EdgeInsets.all(32),
build: (pw.Context context) => items.map((item) => pw.Paragraph(text: item, style: pw.TextStyle(font: font, fontSize: 20))).toList(),
),
);
} catch (e) {
print(e);
}
return pdf;
}

The exported pdf file:

IMG_69186CB64B39-1

Expected characters like that:

IMG_514A58AB155C-1

@ismail-go ismail-go added bug Something isn't working needs triage labels Jan 13, 2025
@robhageboeck
Copy link

@ismail-go Did you discover the cause of this issue?

@leocirto
Copy link

Maybe the problem is the Poppins font. With Montserrat it's apparently working well.

Example:

import 'package:flutter/material.dart';
import 'package:pdf/pdf.dart';
import 'package:pdf/widgets.dart' as pw;
import 'package:printing/printing.dart';
import 'dart:typed_data';

class PdfPreview extends StatelessWidget {
  const PdfPreview4( {super.key} );

  @override
  Widget build(final BuildContext context) {
    return Scaffold(
      appBar: AppBar( title: const Text('Cyrillic Font'), ),
      body: PdfPreview(
        initialPageFormat: PdfPageFormat.a6,
        pageFormats: { 'A6': PdfPageFormat.a6, 'A4': PdfPageFormat.a4 },
        build: (final format) async { return _builPdfPreview( ); },
      ),
    );
  }
}

//======================================================================
// PDF PAGE THEME
//======================================================================
Future<pw.PageTheme> _getPageTheme( ) async{
  return pw.PageTheme(
     theme: pw.ThemeData.withFont(
         base:       await PdfGoogleFonts.montserratRegular(),
         bold:       await PdfGoogleFonts.montserratBold( ),
         italic:     await PdfGoogleFonts.montserratItalic( ),
         boldItalic: await PdfGoogleFonts.montserratBoldItalic( ),
      // icons:      await PdfGoogleFonts.materialIcons(),
        fontFallback: [
              await PdfGoogleFonts.russoOneRegular(),
        ]
     ).copyWith(  textAlign: pw.TextAlign.justify ),
     pageFormat: PdfPageFormat.a6,
     margin: const pw.EdgeInsets.all( 5 ),
  );
}
//======================================================================

//======================================================================
Future<Uint8List> _builPdfPreview( ) async {
  final pdf = pw.Document( );
  pdf.addPage(
     pw.MultiPage(
            pageTheme: await _getPageTheme( ),
            build: (final pw.Context ctx) {
              return [
                 pw.Text('Почти во всех славянских землях вплоть до XI века кириллица использовалась параллельно с глаголицей. У западных славян кириллица быстро вышла из употребления, её заменило латинское письмо. К кириллице же восходят алфавиты почти всех южных (болгарский, сербо-хорватский, македонский) и всех восточных (белорусский, русский, украинский) славянских языков. До 1860-х годов кириллический алфавит использовался для румынского языка'),
                 pw.Text('\n'),
                 pw.Text('В данном списке представлены языки, которые используют или когда-либо использовали алфавит на основе кириллицы. Большая часть символов кириллицы различных языков присутствует в Юникоде (см. Кириллица в Юникоде). '),
              ];
            },
            footer: ( final pw.Context ctx ){
              return pw.Footer(
                     leading: pw.Text('Page ${ctx.pageNumber}/${ctx.pagesCount}'),
              );
            }
     )
  );
  return pdf.save();
}
//======================================================================

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage
Projects
None yet
Development

No branches or pull requests

3 participants