Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/224.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 我试图在颤振应用程序中使用“生成pdf”;Pdf创建库";。在用其他语言生成pdf时,它给出了一个异常_Android_Pdf_Flutter_Dart - Fatal编程技术网

Android 我试图在颤振应用程序中使用“生成pdf”;Pdf创建库";。在用其他语言生成pdf时,它给出了一个异常

Android 我试图在颤振应用程序中使用“生成pdf”;Pdf创建库";。在用其他语言生成pdf时,它给出了一个异常,android,pdf,flutter,dart,Android,Pdf,Flutter,Dart,这是用于以其他语言生成pdf的代码字体: 以下是我在文本中使用已定义字体的方式: 错误日志 E/flatter(26251):[ERROR:flatter/lib/ui/ui\u dart\u state.cc(148)]未处理的异常:“package:pdf/src/font.dart”:失败的断言:第145行位置14:“false”: E/颤振(26251):--------------------------------------------- E/flatter(26251):无法将字

这是用于以其他语言生成pdf的代码字体:

以下是我在文本中使用已定义字体的方式:

错误日志

E/flatter(26251):[ERROR:flatter/lib/ui/ui\u dart\u state.cc(148)]未处理的异常:“package:pdf/src/font.dart”:失败的断言:第145行位置14:“false”:
E/颤振(26251):---------------------------------------------
E/flatter(26251):无法将字符串解码为Latin1。

E/flatter(26251):此字体不支持Unicode字符。 E/flatter(26251):如果您想使用拉丁字符串以外的字符串,请改用TrueType(TTF)字体。
我在尝试使用“pdf创建库”在颤振应用程序中生成pdf时也遇到类似错误。生成pdf时,在我的源文本中有正确的单引号“'”’”

有错误的代码

final String soutceString = 'My source text with " ’ "';

final Document pdf = Document(deflate: zlib.encode);

pdf.addPage(
    MultiPage(
       build: (Context context) => <Widget>[
            Paragraph(text: soutceString),
       ]
    )
);
当我发现错误的符号,我只是更换它

快速修复代码


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

final String sourceString='带“'”的我的源文本';
最终文件pdf=文件(deflate:zlib.encode);
sourceString.replaceAll(“”,“`'),
pdf.addPage(多页)(
构建:(上下文)=>[
段落(文本:sourceString)
]
)
);
但我害怕,未来会出现新的错误符号。我在资产中添加了arial.ttf字体(arial.ttf包含我的符号)并使用它

最适合我的案例

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

import'包:flatter/services.dart'显示rootBundle;
final String sourceString='带“'”的我的源文本';
最终文件pdf=文件(deflate:zlib.encode);
pdf.addPage(多页)(
主题:theme.withFont(
base:Font.ttf(等待rootBundle.load(“assets/arial.ttf”),
粗体:Font.ttf(等待rootBundle.load(“assets/arial.ttf”),
斜体:Font.ttf(等待rootBundle.load(“assets/arial.ttf”),
boldItalic:Font.ttf(等待rootBundle.load(“assets/arial.ttf”),
),
构建:(上下文)=>[
段落(文本:sourceString)
]
)
);

“此字体不支持Unicode字符。”是问题所在。使用支持您需要的字符的字体。我尝试了许多支持马拉地语言的字体,但都不起作用。但是感谢@Henry的建议,我将继续尝试无法解决此问题,最后,我使用了插件,该插件在任何语言中都能很好地工作。此解决方案确实有效。您可以阅读以在项目中插入arial字体API已将Theme.withFont重命名为ThemeData。使用。。。
final String soutceString = 'My source text with " ’ "';

final Document pdf = Document(deflate: zlib.encode);

pdf.addPage(
    MultiPage(
       build: (Context context) => <Widget>[
            Paragraph(text: soutceString),
       ]
    )
);
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. 

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