gradle :
implementation files(‘libs/aspose-cells-24.3-android.via.java.jar’)
@wangyiqun
Would you like to provide executable sample project, sample file and generated PDF file? We will check it soon.
请点击这里查看
An Error Occurs while Converting PPT to PDF in Java on Android - Free Support Forum - aspose.com
The file shared is not a pdf file. The issue is that the SaveFormat
used is not the SaveFomrat
in Aspose.Cells.
Please change it to com.aspose.cells.SaveFormat
in excel2PDF(String inpath)
method.
public static void excel2PDF(String inpath){
// 创建一个Workbook对象并加载XLS文件
InputStream inputStream = null;
try {
inputStream = new FileInputStream(new File(inpath));
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
Workbook doc = null;
try {
doc = new Workbook(inpath);
} catch (Exception e) {
throw new RuntimeException(e);
}
try {
doc.save(inpath+".pdf",com.aspose.cells.SaveFormat.PDF);
} catch (Exception e) {
throw new RuntimeException(e);
}
I appreciate your guidance. I appreciate it. But when I used this code to convert my excel, something else happened to me. When excel has Chinese, Korean, and Japanese, the converted pdf will report errors. see
image.png (10.7 KB)
1.xls.pdf (7.8 KB)
1.xlsx.pdf (7.8 KB)
You can put the used/repuired fonts files into a folder(make sure that the app has the right to get the font files in the folder. Then set the folder to Aspose.Cells at the start.
com.aspsoe.cells.FontConfigs.setFontFolder(fontFolder1, true);
So how do I set what ttf does not report an error? Don’t worry about the font format, but make sure it’s not garbled.
As @peyton.xu replied earlier, you need to place the font files used in a folder and then use com.aspsoe.cells.FontConfigs.setFontFolder
method specifies this folder. Aspose.Cells APIs search the operating system’s default font directory for the required fonts. In case the required fonts are not available in the system’s font directory then the APIs search through the custom (user defined) directories.
Also, if you don’t want to add/copy font files, you may try the following possible Android system font files folders(Make sure that the app has the right to access the folders):
- /system/fonts
- /system/font
- /data/fonts
Code:
FontConfigs.setFontFolders(new String[] {"/system/fonts", "/system/font", "/data/fonts"}, true);
Please note, in this case, the fonts used are different with the ones in the source Excel file. The text appearance may be different with the one in Excel.
Thank you for your reply, but there will be other problems when the above code is added, please check. The numbers are gone, and there’s a problem with the format
屏幕截图 2024-05-20 174354.png (143.8 KB)
@wangyiqun
Thank you for your feedback. We will further investigate your issue. Once there are updates, we will notify you promptly.
Which code did you add for FontConfigs
?
Please also share us the new source Excel file and generated pdf file.
I added this line of code
My complete code is
public static void excel2PDF(String inpath){
try{
FontConfigs.setFontFolders(new String[] {"/system/fonts", "/system/font", "/data/fonts"}, true);
License license = new License();
InputStream open;
open = new FileInputStream(new File("/data/data/com.example.wordpdf2/test/Aspose.Total.Product.Family.lic"));
license.setLicense(open);
Workbook doc;
doc = new Workbook(inpath);
doc.save(inpath+".pdf",com.aspose.cells.SaveFormat.PDF);
}catch (Throwable throwable){
throwable.printStackTrace();
}
}
The zip pack contains my input and output
1.zip (1.2 MB)
@wangyiqun
The input file and output file you provided do not match. Please check and upload the input and output files again. Please refer to the attachment. result.png (94.8 KB)
1.zip (1.2 MB)
My screenshot result.png is wrong, please look at the file in this compressed package
@wangyiqun
By checking your sample file, we found that you used Theme Font. Please refer to the attachment. ThemeFont.png (72.3 KB)
If Theme Font is selected, the font name will display different in different regions . If you do not want that the font is automitally changed in different regions, don’t select the Theme Fonts .
Please review the following document.
The font style is not important to me, how can I modify the code so that the original excel content is retained?
You may open your file into MS Excel manually and then select the data and change the appropriate font (not theme font) and then re-save the file. Now use Aspose.Cells to render to PDF via your original code segment, it will work fine. See the screenshot on how to change the font in MS Excel for your reference.
sc_shot1.png (123.0 KB)
Also, please find attached the updated Excel file and try it. Let us know if you still find any issue with the output PDF file using this input Excel file.
1.zip (7.4 KB)