I am trying to generate pdf in flutter application using " Pdf creation library". While generating pdf in other language it gives exception
I have had similar error when am trying to generate pdf in flutter application using “ Pdf creation library”. While generating pdf have right single quotation mark " ’ " "’" in my source text.
Code with error
final String soutceString = 'My source text with " ’ "';final Document pdf = Document(deflate: zlib.encode);pdf.addPage( MultiPage( build: (Context context) => <Widget>[ Paragraph(text: soutceString), ] ));
Error log
flutter: 'package:pdf/src/font.dart': Failed assertion: line 145 pos 14: 'false':---------------------------------------------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.
When I found wrong symbol I just replace it.
Code with fast fix
final String sourceString = 'My source text with " ’ "';final Document pdf = Document(deflate: zlib.encode);sourceString.replaceAll('’', '`'),pdf.addPage(MultiPage( build: (Context context) => <Widget>[ Paragraph(text: sourceString) ] ));
But I was afraid, of new wrong symbol come in future. I added arial.ttf fonts in to assets (arial.ttf contain my symbol) and use it. Adding assets
Best case for me
import 'package:flutter/services.dart' show rootBundle;final String sourceString = 'My source text with " ’ "';final Document pdf = Document(deflate: zlib.encode);pdf.addPage(MultiPage( theme: Theme.withFont( base: Font.ttf(await rootBundle.load("assets/arial.ttf")), bold: Font.ttf(await rootBundle.load("assets/arial.ttf")), italic: Font.ttf(await rootBundle.load("assets/arial.ttf")), boldItalic: Font.ttf(await rootBundle.load("assets/arial.ttf")), ), build: (Context context) => <Widget>[ Paragraph(text: sourceString) ] ));