问题描述
- 在Vivo X9 Android手机上,设置字体目录抛出异常
代码如下:
private static void addFontForAsposeCells() {
ArrayList<String> fontDirs = new ArrayList<>();
fontDirs.add("/system/fonts");
fontDirs.add("/system/font");
fontDirs.add("/data/fonts");
fontDirs = filterValid(fontDirs);
try {
CellsHelper.setFontDirs(fontDirs);
} catch (Exception e) {
Log.e("PdfRendererPlugin", "Can not add font dirs", e);
}
}
private static ArrayList<String> filterValid(ArrayList<String> dirs) {
final ArrayList<String> ret = new ArrayList<>();
dirs.forEach(new Consumer<String>() {
@Override
public void accept(String dir) {
File file = new File(dir);
if (file.exists()) {
ret.add(dir);
Log.d("PdfRendererPlugin", "Valid font dir " + dir);
}
}
});
return ret;
}
异常信息如下:
D/PdfRendererPlugin(20229): Valid font dir /system/fonts
D/PdfRendererPlugin(20229): Valid font dir /data/fonts
E/PdfRendererPlugin(20229): Can not add font dirs
E/PdfRendererPlugin(20229): java.lang.NullPointerException: Attempt to get length of null array
E/PdfRendererPlugin(20229): at com.aspose.cells.a.c.zae.a(Unknown Source)
E/PdfRendererPlugin(20229): at com.aspose.cells.FolderFontSource.b(Unknown Source)
E/PdfRendererPlugin(20229): at com.aspose.cells.FontConfigs.b(Unknown Source)
E/PdfRendererPlugin(20229): at com.aspose.cells.FontConfigs.a(Unknown Source)
E/PdfRendererPlugin(20229): at com.aspose.cells.FontConfigs.a(Unknown Source)
E/PdfRendererPlugin(20229): at com.aspose.cells.CellsHelper.setFontDirs(Unknown Source)
E/PdfRendererPlugin(20229): at com.afterqcd.document_renderer.DocumentRendererPlugin.addFontForAsposeCells(DocumentRendererPlugin.java:89)
- Excel导出成PDF时,无异常,但中文全部是乱码
代码如下:
Workbook workbook = new Workbook(request.path);
com.aspose.cells.PdfSaveOptions pdfSaveOptions = new com.aspose.cells.PdfSaveOptions();
pdfSaveOptions.setOnePagePerSheet(true);
pdfSaveOptions.setCalculateFormula(true);
workbook.save(pdfFile.getAbsolutePath(), pdfSaveOptions);
Log.d("PdfRendererPlugin", "Created pdf file " + pdfFile.getAbsolutePath());
环境信息
-
Aspose.Cells
aspose-cells-19.12-android.via.java.jar
-
手机及系统
型号 vivo X9
Android版本 7.1.2
Android安全补丁程序级别 2019-10-01
vivo ROM Funtouch OS_3.1
软件版本好 PD1616_D_7.16.35
编译时间 2019-12-02
@afterqcd,
感谢您的查询。您使用的是较旧的版本,因此您可以使用产品的最新版本尝试该方案。
如果问题仍未解决,请与我们共享一个简化的可编译/可运行项目,该项目可在此处用于测试方案。在执行此测试的位置共享您的环境详细信息。您是否在其他智能手机上测试了此问题以进行确认?
共享测试2中使用的模板Excel文件,以转换为PDF。如果可能,请将该测试也作为申请第一期的申请的一部分。
这将有助于尽早在此处重现该问题,并为您提供相应的帮助。
您好,已将aspose.cells.android.via.java更新到20.3进行测试,依然存在上面的两个问题。
问题1的异常堆栈信息如下:
E/PdfRendererPlugin(29319): java.lang.NullPointerException: Attempt to get length of null array
E/PdfRendererPlugin(29319): at com.aspose.cells.a.c.zaf.a(Unknown Source)
E/PdfRendererPlugin(29319): at com.aspose.cells.FolderFontSource.b(Unknown Source)
E/PdfRendererPlugin(29319): at com.aspose.cells.FontConfigs.b(Unknown Source)
E/PdfRendererPlugin(29319): at com.aspose.cells.FontConfigs.a(Unknown Source)
E/PdfRendererPlugin(29319): at com.aspose.cells.FontConfigs.a(Unknown Source)
E/PdfRendererPlugin(29319): at com.aspose.cells.CellsHelper.setFontDirs(Unknown Source)
E/PdfRendererPlugin(29319): at com.afterqcd.document_renderer.DocumentRendererPlugin.addFontForAsposeCells(DocumentRendererPlugin.java:89)
同样的代码在vivo X9上运行不正常,但在小米6s和华为P30 Pro上正常,说明
- 调用端代码处理流程不存在问题
- 问题的根本在于aspose.cells无法在vivo X9上正常工作
麻烦推进解决,谢谢。
@afterqcd,
我们已经了解了这个问题,但是我们需要进一步研究。我们已将该问题记录在数据库中以进行调查和修复。一次,我们将为您提供一些新闻,我们将在本主题中为您更新。
此问题已记录为
CELLSANDROID-100 – Aspose.Cells for Java.Android 20.3 does not work on Vivo X9
@afterqcd,
问题1:
设备Vivo X9上的字体文件夹“ / system / fonts”,“ / system / font”,“ / data / fonts”似乎不是目录,而是文件。在解决此问题之前,您可以将函数filterValid更改为以下代码,以作为解决方法。
private static ArrayList<String> filterValid(ArrayList<String> dirs) {
final ArrayList<String> ret = new ArrayList<>();
dirs.forEach(new Consumer<String>() {
@Override
public void accept(String dir) {
File file = new File(dir);
if (file.exists() && file.isDirectory()) {
File[] subFiles = file.listFiles();
if(subFiles != null) {
ret.add(dir);
Log.d("PdfRendererPlugin", "Valid font dir " + dir);
}
}
}
});
return ret;
}
问题2:
仅在设备Vivo X9上会发生此问题吗?还是在您提到的设备(小米6s和华为P30 Pro)上也发生了?
请通过“ Aspose.Cells for Java.Android 20.3”与我们共享源文件和转换后的pdf文件,以分析问题。
您好,
- 问题1
按建议添加了file.isDirectory的测试,问题依然没有解决。
代码
private static ArrayList<String> filterValid(ArrayList<String> dirs) {
final ArrayList<String> ret = new ArrayList<>();
dirs.forEach(new Consumer<String>() {
@Override
public void accept(String dir) {
File file = new File(dir);
if (file.exists() && file.isDirectory()) {
ret.add(dir);
Log.d("PdfRendererPlugin", "Valid font dir " + dir);
}
}
});
return ret;
}
日志和异常
D/PdfRendererPlugin( 8291): Valid font dir /system/fonts
D/PdfRendererPlugin( 8291): Valid font dir /data/fonts
E/PdfRendererPlugin( 8291): Can not add font dirs
E/PdfRendererPlugin( 8291): java.lang.NullPointerException: Attempt to get length of null array
E/PdfRendererPlugin( 8291): at com.aspose.cells.a.c.zaf.a(Unknown Source)
E/PdfRendererPlugin( 8291): at com.aspose.cells.FolderFontSource.b(Unknown Source)
E/PdfRendererPlugin( 8291): at com.aspose.cells.FontConfigs.b(Unknown Source)
E/PdfRendererPlugin( 8291): at com.aspose.cells.FontConfigs.a(Unknown Source)
E/PdfRendererPlugin( 8291): at com.aspose.cells.FontConfigs.a(Unknown Source)
E/PdfRendererPlugin( 8291): at com.aspose.cells.CellsHelper.setFontDirs(Unknown Source)
E/PdfRendererPlugin( 8291): at com.afterqcd.document_renderer.DocumentRendererPlugin.addFontForAsposeCells(DocumentRendererPlugin.java:89)
- 问题2
之前的交流已说的足够明确,小米6s和P30 Pro没有这个问题,仅在Vivo X9上存在。源文件与PDF,如下:
测试文件.zip (79.3 KB)
@afterqcd,
感谢您的反馈。我们正在分析此信息,并将在处理此问题时予以考虑。
@afterqcd,
对于问题1:
请注意,我们在建议的代码中也执行了if(subFiles!= null)检查。
Vivo X9似乎有一些限制,即您无法从“ / system / fonts”或“ / data / fonts”获取字体文件。 您可以使用以下代码进行检查:
//dir is "/system/fonts" or "/data/fonts"
File file = new File(dir);
if (file.exists() && file.isDirectory()) {
File[] subFiles = file.listFiles();
if(subFiles != null) {
//you can list font files here
}
}
对于问题2,我们检查了您的共享文件,这是字体问题。 可以设置有效的字体文件夹后,一切都应该没问题。
加了subFiles的判断后,两个问题都解决了,非常感谢。
@afterqcd,
很高兴知道您的问题已按照建议的代码行进行了整理。如果您需要进一步的帮助或有其他问题或疑问,请随时与我们联系,我们将竭诚为您服务。
@afterqcd,
我们将在lib中进行以下检查:
File[] subFiles = file.listFiles();
if(subFiles != null)
{
//...
}