We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

The character of WordArt is missing in the result of saving in HTML format

Hi there


We are currently testing saving Excel files into HTML format with Aspose Cells 17.4.0 in Linux environment.
Here is out code for test:

Workbook book = null;
if (StringUtils.isNotEmpty(password)) {
LoadOptions loadOps = new LoadOptions();
loadOps.setPassword(password);
book = new Workbook(filePath, loadOps);
} else {
book = new Workbook(filePath);
}

final String dirName = UUID.randomUUID().toString();
File file = new File("" + dirName);
file.mkdirs();

for (int page = 0; page < book.getWorksheets().getCount(); page++) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
book.getWorksheets().get(page).setVisible(true);

for (int i = 0; i < book.getWorksheets().getCount(); i++) {
if (i != page) {
book.getWorksheets().get(i).setVisible(false);
}
}
HtmlSaveOptions saveOps = new HtmlSaveOptions();
saveOps.setClearData(false);
saveOps.setCreateDirectory(false);
saveOps.setExportActiveWorksheetOnly(false);
saveOps.setExportHiddenWorksheet(false);
saveOps.setParseHtmlTagInCell(true);
saveOps.setEncoding(Encoding.getUTF8());
saveOps.setHiddenRowDisplayType(HtmlHiddenRowDisplayType.REMOVE);
saveOps.setHiddenColDisplayType(HtmlHiddenColDisplayType.REMOVE);
saveOps.setExportImagesAsBase64(true);
saveOps.setHtmlCrossStringType(HtmlCrossType.CROSS);

saveOps.setStreamProvider(new IStreamProvider() {

@Override
public void initStream(StreamProviderOptions arg0) throws Exception {
arg0.setStream(new ByteArrayOutputStream());
}

@Override
public void closeStream(StreamProviderOptions arg0) throws Exception {
System.out.println(arg0.getDefaultPath());
OutputStream stream = arg0.getStream();
if (stream instanceof ByteArrayOutputStream) {
ByteArrayOutputStream bb = (ByteArrayOutputStream) stream;
IOUtils.write(bb.toByteArray(), new FileOutputStream(dirName + “/” + arg0.getDefaultPath()));
}
}
});
book.save(baos, saveOps);
IOUtils.write(baos.toByteArray(), new FileOutputStream(dirName + “/” + (page + 1) + “.html”));
}

In the result, there is an missing Chinese character.
I have uploaded the Excel file and the result, and the password for the file is “123456”.
Please check the attachment and help us solve this issue, thank you~

Craig

Hi Craig,


Thank you for contacting Aspose support.

I have evaluated the presented scenario on Windows 7 as well as Ubuntu 15.10 while using the latest version of Aspose.Cells for Java 17.1.10. As per my test results, I can confirm that the said issue (missing Chinese character in HTML) is caused due to unavailability of the required font. Please note, the character in question is using the PMingLiU font (you can confirm this by selecting the character in Excel application). Please note, the aforementioned font is not present in Unix environments by default so there are 2 possible solutions to the said problem.

  1. Acquire the said font and place it in any directory on Unix system, then explicitly tell the Aspose.Cells APIs where you have placed the font. You can use any of the appropriate methods from the FontConfigs class to set the font file or its directory.
  2. If you are not able to find the exact required font, you can also set the substitution in your code, that is; direct the Aspose.Cells APIs to use another available font that could render the glyph in question. The FontConfigs class offers the setFontSubstitutes method to set the font substitutions.

Attached to this post is an archive containing the HTML which I have generated by substituting the PMingLiU font with Arial Unicode MS on Ubuntu 15.10.

Hi Babar.Raza


Thanks for your infomation.

To apply these 2 solution, I added some modification at the block before the code I mentioned like:
/*
* Font config block
/

Workbook book = null;
if (StringUtils.isNotEmpty(password)) {
LoadOptions loadOps = new LoadOptions();
loadOps.setPassword(password);
book = new Workbook(filePath, loadOps);
} else {
book = new Workbook(filePath);
}


For solution #1 I added following code:
FontConfigs.setFontFolder("/usr/share/fonts/forread", true);

For solution #2 I added following code:
FontConfigs.setFontSubstitutes(“PMingLiU”, new String[] { “Arial” });

And then I tried another way as solution #3:
FontConfigs.setDefaultFontName(“Noto Sans CJK Regular”);

This problem still remains with 17.1.10.

And following is the information about the environment running the test.

uname -a
Linux d1ars04.novalocal 3.10.0-327.18.2.el7.x86_64 #1 SMP Thu May 12 11:03:55 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

cat /etc/-release
CentOS Linux release 7.2.1511 (Core)
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"

CentOS Linux release 7.2.1511 (Core)
CentOS Linux release 7.2.1511 (Core)

java -version
java version "1.7.0_101"
OpenJDK Runtime Environment (rhel-2.6.6.1.el7_2-x86_64 u101-b00)
OpenJDK 64-Bit Server VM (build 24.95-b01, mixed mode)

fc-list
/usr/share/fonts/forread/TW-Sung-98_1.ttf: TW-Sung,全字庫正宋體:style=Regular
/usr/share/fonts/forread/TW-Kai-Ext-B-98_1.ttf: TW-Kai-Ext-B,全字庫正楷體 Ext-B:style=Regular
/usr/share/fonts/forread/MSJHBD.TTC: Microsoft JhengHei,微軟正黑體:style=Negreta,Bold,tučné,fed,Fett,Έντονα,Negrita,Lihavoitu,Gras,Félkövér,Grassetto,Vet,Halvfet,Pogrubiony,Negrito,Полужирный,Fet,Kalın,Krepko,Lodia
/usr/share/fonts/forread/wt011.ttf: HanWangHeiLight,王漢宗細黑體繁:style=Regular
/usr/share/X11/fonts/Type1/c0611bt_.pfb: Courier 10 Pitch:style=Bold Italic
/usr/share/X11/fonts/Type1/UTBI____.pfa: Utopia:style=Bold Italic
/usr/share/fonts/forread/msgothic.ttc: MS Gothic,MS ゴシック:style=Regular,標準
/usr/share/fonts/forread/msgothic.ttc: MS UI Gothic:style=Regular,標準
/usr/share/fonts/forread/timesbi.ttf: Times New Roman:style=Bold Italic,Negreta cursiva,tučné kurzíva,fed kursiv,Fett Kursiv,Έντονα Πλάγια,Negrita Cursiva,Lihavoitu Kursivoi,Gras Italique,Félkövér dőlt,Grassetto Corsivo,Vet Cursief,Halvfet Kursiv,Pogrubiona kursywa,Negrito Itálico,Полужирный Курсив,Tučná kurzíva,Fet Kursiv,Kalın İtalik,Krepko poševno,nghiêng đậm,Lodi etzana
/usr/share/X11/fonts/Type1/c0419bt_.pfb: Courier 10 Pitch:style=Regular
/usr/share/fonts/forread/MSJHBD.TTC: Microsoft JhengHei UI:style=Negreta,Bold,tučné,fed,Fett,Έντονα,Negrita,Lihavoitu,Gras,Félkövér,Grassetto,Vet,Halvfet,Pogrubiony,Negrito,Полужирный,Fet,Kalın,Krepko,Lodia
/usr/share/fonts/forread/WINGDING.TTF: Wingdings:style=Regular,normal,Standard,Normaali,Normale,Standaard,Normálne,Navadno
/usr/share/fonts/forread/ARIALNBI.TTF: Arial,Arial Narrow:style=Narrow,Negreta cursiva,tučné kurzíva,fed kursiv,Fett Kursiv,Έντονα Πλάγια,Bold Italic,Negrita Cursiva,Lihavoitu Kursivoi,Gras Italique,Félkövér dőlt,Grassetto Corsivo,Vet Cursief,Halvfet Kursiv,Pogrubiona kursywa,Negrito Itálico,Полужирный Курсив,Tučná kurzíva,Fet Kursiv,Kalın İtalik,Krepko poševno,Lodi etzana
/usr/share/fonts/forread/MSJH.TTC: Microsoft JhengHei UI:style=Normal,Regular,obyčejné,Standard,Κανονικά,Normaali,Normál,Normale,Standaard,Normalny,Обычный,Normálne,Navadno,Arrunta
/usr/share/fonts/forread/arialbi.ttf: Arial:style=Bold Italic,Negreta cursiva,tučné kurzíva,fed kursiv,Fett Kursiv,Έντονα Πλάγια,Negrita Cursiva,Lihavoitu Kursivoi,Gras Italique,Félkövér dőlt,Grassetto Corsivo,Vet Cursief,Halvfet Kursiv,Pogrubiona kursywa,Negrito Itálico,Полужирный Курсив,Tučná kurzíva,Fet Kursiv,Kalın İtalik,Krepko poševno,nghiêng đậm,Lodi etzana
/usr/share/fonts/forread/arialbd.ttf: Arial:style=Bold,Negreta,tučné,fed,Fett,Έντονα,Negrita,Lihavoitu,Gras,Félkövér,Grassetto,Vet,Halvfet,Pogrubiony,Negrito,Полужирный,Fet,Kalın,Krepko,đậm,Lodia
/usr/share/fonts/forread/mingliub.ttc: PMingLiU-ExtB,新細明體-ExtB:style=Regular
/usr/share/X11/fonts/Type1/c0648bt_.pfb: Bitstream Charter:style=Regular
/usr/share/fonts/forread/wt001.ttf: HanWangMingLight,王漢宗細明體繁:style=Regular
/usr/share/fonts/forread/WEBDINGS.TTF: Webdings:style=Regular,Normal,obyčejné,Standard,Κανονικά,Normaali,Normál,Normale,Standaard,Normalny,Обычный,Normálne,Navadno,Arrunta
/usr/share/fonts/forread/ARIALNB.TTF: Arial,Arial Narrow:style=Narrow,Negreta,tučné,fed,Fett,Έντονα,Bold,Negrita,Lihavoitu,Gras,Félkövér,Grassetto,Vet,Halvfet,Pogrubiony,Negrito,Полужирный,Fet,Kalın,Krepko,Lodia
/usr/share/fonts/forread/MSJH.TTC: Microsoft JhengHei,微軟正黑體:style=Normal,Regular,obyčejné,Standard,Κανονικά,Normaali,Normál,Normale,Standaard,Normalny,Обычный,Normálne,Navadno,Arrunta
/usr/share/fonts/forread/times.ttf: Times New Roman:style=Regular,Normal,obyčejné,Standard,Κανονικά,Normaali,Normál,Normale,Standaard,Normalny,Обычный,Normálne,Navadno,thường,Arrunta
/usr/share/fonts/forread/MSJHL.TTC: Microsoft JhengHei UI,Microsoft JhengHei UI Light:style=Light,Regular
/usr/share/fonts/forread/NotoSansCJKtc-Regular.otf: Noto Sans CJK TC,Noto Sans CJK TC Regular:style=Regular
/usr/share/fonts/opensymbol/opens___.ttf: OpenSymbol:style=Regular
/usr/share/fonts/forread/MSJHL.TTC: Microsoft JhengHei,微軟正黑體,微軟正黑體 Light,Microsoft JhengHei Light:style=Light,Regular
/usr/share/fonts/forread/timesbd.ttf: Times New Roman:style=Bold,Negreta,tučné,fed,Fett,Έντονα,Negrita,Lihavoitu,Gras,Félkövér,Grassetto,Vet,Halvfet,Pogrubiona,Negrito,Полужирный,Fet,Kalın,Krepko,đậm,Lodia
/usr/share/fonts/forread/mingliub.ttc: MingLiU_HKSCS-ExtB,細明體_HKSCS-ExtB:style=Regular
/usr/share/X11/fonts/Type1/cursor.pfa: Cursor:style=Regular
/usr/share/X11/fonts/Type1/UTB_____.pfa: Utopia:style=Bold
/usr/share/X11/fonts/Type1/c0583bt_.pfb: Courier 10 Pitch:style=Bold
/usr/share/fonts/forread/arial.ttf: Arial:style=Regular,Normal,obyčejné,Standard,Κανονικά,Normaali,Normál,Normale,Standaard,Normalny,Обычный,Normálne,Navadno,thường,Arrunta
/usr/share/fonts/forread/timesi.ttf: Times New Roman:style=Italic,cursiva,kurzíva,kursiv,Πλάγια,Kursivoitu,Italique,Dőlt,Corsivo,Cursief,kursywa,Itálico,Курсив,İtalik,Poševno,nghiêng,Etzana
/usr/share/fonts/forread/ARIALNI.TTF: Arial,Arial Narrow:style=Narrow,Cursiva,kurzíva,kursiv,Πλάγια,Italic,Kursivoitu,Italique,Dőlt,Corsivo,Cursief,Kursywa,Itálico,Курсив,İtalik,Poševno,Etzana
/usr/share/X11/fonts/Type1/UTI_____.pfa: Utopia:style=Italic
/usr/share/fonts/forread/mingliub.ttc: MingLiU-ExtB,細明體-ExtB:style=Regular
/usr/share/fonts/forread/ariblk.ttf: Arial,Arial Black:style=Black,Normal,obyčejné,Standard,Κανονικά,Regular,Normaali,Normál,Normale,Standaard,Normalny,Обычный,Normálne,Navadno,Arrunta
/usr/share/fonts/forread/ariali.ttf: Arial:style=Italic,Cursiva,kurzíva,kursiv,Πλάγια,Kursivoitu,Italique,Dőlt,Corsivo,Cursief,Kursywa,Itálico,Курсив,İtalik,Poševno,nghiêng,Etzana
/usr/share/X11/fonts/Type1/c0582bt_.pfb: Courier 10 Pitch:style=Italic
/usr/share/fonts/forread/msgothic.ttc: MS PGothic,MS Pゴシック:style=Regular,標準
/usr/share/fonts/forread/TW-Kai-Plus-98_1.ttf: TW-Kai-Plus,全字庫正楷體 Plus:style=Regular
/usr/share/fonts/forread/wt006.ttf: HanWangYenLight,王漢宗細圓體繁:style=Regular
/usr/share/fonts/forread/TW-Kai-98_1.ttf: TW-Kai,全字庫正楷體:style=Regular
/usr/share/X11/fonts/Type1/c0633bt_.pfb: Bitstream Charter:style=Bold Italic
/usr/share/fonts/forread/ARIALN.TTF: Arial,Arial Narrow:style=Narrow,Normal,obyčejné,Standard,Κανονικά,Regular,Normaali,Normál,Normale,Standaard,Normalny,Обычный,Normálne,Navadno,Arrunta
/usr/share/X11/fonts/Type1/c0649bt_.pfb: Bitstream Charter:style=Italic
/usr/share/X11/fonts/Type1/c0632bt_.pfb: Bitstream Charter:style=Bold
/usr/share/X11/fonts/Type1/UTRG____.pfa: Utopia:style=Regular

There are also fonts’ file in the attachment.
Please rename the files like “fonts.7z.001” first, and then unzip it.

Please check this information again, thankyou~

Craig


Hi Craig,


Thank you for writing back.

I have checked the list of fonts from your machine, and I have noticed that your machine currently do not have the Arial Unicode MS font available. Please check the attached archive for the aforementioned font file. Please extract the archive in your existing font folder, and use the following piece of code to set the font location as well as specify the font substitution.

In case the problem persists, please share the resultant HTML and PDF file (use Workbook.save method with appropriate SaveFormat constant to save the result in PDF). Please note, it is easy to detect what fonts have been used by the API by reviewing the PDF document properties.

Java

Properties props = System.getProperties();
props.setProperty(“Aspose.Cells.FontDirExc”, “/home/babar/Downloads/font”);

com.aspose.cells.FontConfigs.setFontSubstitutes(“PMingLiu”, new String[] {“Arial Unicode MS”});

Hi Babar.Raza


I put your font file in the machine, and add the following code below:
Properties props = System.getProperties();
props.setProperty(“Aspose.Cells.FontDirExc”, “/usr/share/fonts/forread”);

System.out.println(“replace”);
com.aspose.cells.FontConfigs.setFontSubstitutes(“PMingLiu”, new String[] {“Arial Unicode MS”});

The problem still remains.
P.S. The font used for font replacement has to be “Arial Unicode MS”?


Craig

Hi again,


Adding more to my previous response, I have also noticed that you have MingLiU-ExtB font available on your machine therefore you can use it as substitution. Please check the following statement and its resultant HTML as attached. Please note, you still need to set the font folder in this case.

Java

com.aspose.cells.FontConfigs.setFontSubstitutes(“PMingLiu”, new String[] {“MingLiu-ExtB”});
Hi there,

craig.w.su:

I put your font file in the machine, and add the following code below:
Properties props = System.getProperties();
props.setProperty("Aspose.Cells.FontDirExc", "/usr/share/fonts/forread");

System.out.println("replace");
com.aspose.cells.FontConfigs.setFontSubstitutes("PMingLiu", new String[] {"Arial Unicode MS"});

The problem still remains.
P.S. The font used for font replacement has to be "Arial Unicode MS"?


Sorry, I just saw your recent test results. Please note, I am suggesting you to use the Arial Unicode MS font as a substitution because as per my testing this font can render the glyph in question. You can alternatively use the MingLiu-ExtB font but the result against Arial Unicode MS font is much better than the result generated against MingLiu-ExtB. Please check my previous post for the attachment.

That said, I am not sure why you are seeing the incorrect result even though your are specifying the font substitution. Please share the PDF file that you may generate by using the Workbook.save method after setting the font substitution so I may review the scenario for used fonts.

Hi Babar.Raza


I modified my font configuration code like this:
Properties props = System.getProperties();
props.setProperty(“Aspose.Cells.FontDirExc”, “/usr/share/fonts/forread”);

FontConfigs.setFontFolder("/usr/share/fonts/forread", true);
System.out.println(“replace”);
com.aspose.cells.FontConfigs.setFontSubstitutes(“PMingLiu”, new String[] {“MingLiu-ExtB”});

However the problem still remains.

Craig

Hi Babar.Raza


Please check the attachment, thank you

Hi Craig,


Please share the PDF file generated after substitution the font with Arial Unicode MS and MingLiu-ExtB. Moreover, in your recent code, you are setting the fonts location multiple times. Please note, if you use the Aspose.Cells.FontDirExc parameter with system’s properties, that mean, you do not wish the API to search any more font folders on the system, that is, you are restricting the API to load fonts from a single location. On the other hand, the FontConfigs.setFontFolder allows the API to pick fonts from a particular location but does not restrict the API to check other system’s font locations.
Hi again,

craig.w.su:
Please check the attachment, thank you

Just checked your PDF and it seems that both Arial Unicode MS and MingLiU-ExtB fonts have not been used for rendering. Could you please perform a few more tests by using another font folder where you should only place the Arial Unicode MS font file? Please set the new font location using the following statements and save the result directly in PDF format to share it here. Moreover, if you can see the problematic glyph correctly rendered in PDF, please use the same approach/font folder to render the spreadsheet in HTML format as well.

Thank you for your cooperation in troubleshooting this scenario.

Java

Properties props = System.getProperties();
props.setProperty("Aspose.Cells.FontDirExc", "/home/babar/Downloads/PMingLiu");

Workbook book = null;
String password = "123456";

LoadOptions loadOps = new LoadOptions();
loadOps.setPassword(password);
book = new Workbook(dir + "XL_007_2_locked.xlsx", loadOps);
com.aspose.cells.FontConfigs.setFontSubstitutes("PMingLiu", new String[] {"Arial Unicode MS"});
book.save(dir + "Arial Unicode MS.pdf", SaveFormat.PDF);

Hi Babar.Raza


I modified my code as following to generate pdf files and the converted html result:
FontConfigs.setFontFolder("/usr/share/fonts/forread", true);
System.out.println(“replace”);
com.aspose.cells.FontConfigs.setFontSubstitutes(“PMingLiu”, new String[] {“MingLiu-ExtB”});

Workbook book = null;
if (StringUtils.isNotEmpty(password)) {
LoadOptions loadOps = new LoadOptions();
loadOps.setPassword(password);
book = new Workbook(filePath, loadOps);
} else {
book = new Workbook(filePath);
}

book.save(“font_sub_”+filePath+".pdf", SaveFormat.PDF);

final String dirName = UUID.randomUUID().toString();
File file = new File("" + dirName);
file.mkdirs();

for (int page = 0; page < book.getWorksheets().getCount(); page++) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
book.getWorksheets().get(page).setVisible(true);

for (int i = 0; i < book.getWorksheets().getCount(); i++) {
if (i != page) {
book.getWorksheets().get(i).setVisible(false);
}
}
HtmlSaveOptions saveOps = new HtmlSaveOptions();
saveOps.setClearData(false);
saveOps.setCreateDirectory(false);
saveOps.setExportActiveWorksheetOnly(false);
saveOps.setExportHiddenWorksheet(false);
saveOps.setParseHtmlTagInCell(true);
saveOps.setEncoding(Encoding.getUTF8());
saveOps.setHiddenRowDisplayType(HtmlHiddenRowDisplayType.REMOVE);
saveOps.setHiddenColDisplayType(HtmlHiddenColDisplayType.REMOVE);
saveOps.setExportImagesAsBase64(true);
saveOps.setHtmlCrossStringType(HtmlCrossType.CROSS);

saveOps.setStreamProvider(new IStreamProvider() {

@Override
public void initStream(StreamProviderOptions arg0) throws Exception {
arg0.setStream(new ByteArrayOutputStream());
}

@Override
public void closeStream(StreamProviderOptions arg0) throws Exception {
System.out.println(arg0.getDefaultPath());
OutputStream stream = arg0.getStream();
if (stream instanceof ByteArrayOutputStream) {
ByteArrayOutputStream bb = (ByteArrayOutputStream) stream;
IOUtils.write(bb.toByteArray(), new FileOutputStream(dirName + “/” + arg0.getDefaultPath()));
}
}
});
book.save(baos, saveOps);
IOUtils.write(baos.toByteArray(), new FileOutputStream(dirName + “/” + (page + 1) + “.html”));
}

In the html result, the Chinese character is still missing.
Please check the attachment.


Craig


Hi Craig,


I have checked the recent results and I can see that the problematic glyph has not rendered at all. Could you please check my last response and perform the test on your end with the provided code snippet?

Hi again,


Adding more to my previous response, please add the calibri.ttf & calirib.ttf file along with arialuni.ttf in a new folder and execute the code share here. Please note, the WordArt in question uses 2 fonts (Calibri & PMingLiU) where contents styled with Calibri font should render in same font whereas PMingLiU should be substituted with Arial Unicode MS to give correct output in PDF as well as HTML formats.

Hi Babar.Raza


I used the code you provided and make a little modification:

String dir = “./”;

Properties props = System.getProperties();
props.setProperty(“Aspose.Cells.FontDirExc”, “/home/cs3l@jan.corp/onefont”);

Workbook book = null;
String password = “123456”;

LoadOptions loadOps = new LoadOptions();
loadOps.setPassword(password);
book = new Workbook(dir + “XL_007_2_locked.xlsx”, loadOps);
com.aspose.cells.FontConfigs.setFontSubstitutes(“PMingLiu”, new String[] {“Arial Unicode MS”});
book.save(dir + “Arial Unicode MS.pdf”, SaveFormat.PDF);


I put the only one font file in the folder and save it into PDF format
Please check the result in the attachment and whether I am right understanding about your reply, thank you~

Craig

Hi Craig,


Thank you for your continues support in isolating the problem cause for this scenario. I have checked your PDF, and I can see that the glyph in question has rendered correctly in the PDF. Moreover, Arial Unicode MS font has been embedded in the PDF (can be verified by checking the PDF’s Document Properties > Fonts). Please note, the problematic glyph is currently overlapping the contents before it. This is because those contents before the problematic glyph have been styled with Calibri font which we have skipped for now just for testing purposes. In your next test, please add the calibri.ttf & calirib.ttf file along with arialuni.ttf in a new folder and execute the following code after only changing the path to 3 font files. You should be getting the result as attached.

Java
Properties props = System.getProperties();
props.setProperty(“Aspose.Cells.FontDirExc”, “/home/babar/Downloads/fonts”);
Workbook book = null;
String password = “123456”;
LoadOptions loadOps = new LoadOptions();
loadOps.setPassword(password);
book = new Workbook(dir + “XL_007_2_locked.xlsx”, loadOps);

com.aspose.cells.FontConfigs.setFontSubstitutes(“PMingLiu”, new String[] {“Arial Unicode MS”});
book.save(dir + “Arial Unicode MS.pdf”, SaveFormat.PDF);

final String dirName = UUID.randomUUID().toString();

File file = new File("" + dirName);
file.mkdirs();

for (int page = 0; page < book.getWorksheets().getCount(); page++) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
book.getWorksheets().get(page).setVisible(true);

for (int i = 0; i < book.getWorksheets().getCount(); i++) {
if (i != page) {
book.getWorksheets().get(i).setVisible(false);
}
}
HtmlSaveOptions saveOps = new HtmlSaveOptions();
saveOps.setClearData(false);
saveOps.setCreateDirectory(false);
saveOps.setExportActiveWorksheetOnly(false);
saveOps.setExportHiddenWorksheet(false);
saveOps.setParseHtmlTagInCell(true);
saveOps.setEncoding(Encoding.getUTF8());
saveOps.setHiddenRowDisplayType(HtmlHiddenRowDisplayType.REMOVE);
saveOps.setHiddenColDisplayType(HtmlHiddenColDisplayType.REMOVE);
saveOps.setExportImagesAsBase64(true);
saveOps.setHtmlCrossStringType(HtmlCrossType.CROSS);
saveOps.setStreamProvider(new IStreamProvider() {

public void initStream(StreamProviderOptions arg0) throws Exception {
arg0.setStream(new ByteArrayOutputStream());
}
public void closeStream(StreamProviderOptions arg0) throws Exception {
System.out.println(arg0.getDefaultPath());
OutputStream stream = arg0.getStream();
if (stream instanceof ByteArrayOutputStream) {
ByteArrayOutputStream bb = (ByteArrayOutputStream) stream;
IOUtils.write(bb.toByteArray(), new FileOutputStream(dirName + “/” + arg0.getDefaultPath()));
}
}
});
book.save(baos, saveOps);
IOUtils.write(baos.toByteArray(), new FileOutputStream(dirName + “/” + (page + 1) + “.html”));

Hi Babar.Raza


Thanks for the help~
I tried this way and the Chinese character did show up in the HTML result.
However this way seem to be a particular solution for this file.

Is it possible to use some kind of default font for rendering instead of substitution of some specific fonts when this kind of problem happens?

We have a folder under /usr/share/fonts, and installed fonts in there.
Can we put these fonts in there instead creating a specific folder and put particular fonts?

Craig

Hi Craig,


Thank you for the feedback, and it is good to know that you are able to get the expected results.

We have a folder under /usr/share/fonts, and installed fonts in there.
Can we put these fonts in there instead creating a specific folder and put particular fonts?

Regarding your concerns as quoted above, first of all, please note that Aspose.Cells for Java API scans the “/usr/share/fonts” directory and its sub directories for font files (TTF & TTC) as a default behaviour. That means, if you place all the required fonts on aforementioned location, you do not need to explicitly set the font location in your code. The Aspose.Cells APIs will pick all available fonts and use them for rendering purposes wherever required.

Regarding the original problem. please note, the said issue occurred because you are missing the required fonts (Calibri & PMingLiU) in your environment therefore the API substitutes the font and as a result there is change in the layout, that is; problematic character has been pushed to the next line of the WordArt (clearly visible in PDF results). If all of the required fonts are present, you should get the same result as of Excel’s Print Preview. In case you are not able to acquire or place the required fonts in the environment, the alternative solution is to specify the font substitution yourself. This way, you can tell the API which alternative fonts should be used in case a specific font is not present. If you do not specify a font substitution, you can also rely on the font substitution mechanism of Aspose.Cells APIs because these APIs decide the substituted font on the fact if the substituted font can render all the characters for a particular text segment (specifically for shape to image module).

Is it possible to use some kind of default font for rendering instead of substitution of some specific fonts when this kind of problem happens?

I am afraid, the above is not possible. Reason being, there is no font that could render all possible characters from all possible languages.

Hi Babar.Raza


Thanks for your information.

About problem 1, as my understanding, the result can be rendered correctly, If we can find the specific fonts it need for rendering and put them in “/usr/share/fonts” or its subdirectories, right?

About problem 2, I know there is no fonts can be used for rendering in all languages, but I want to know that whether there is a method to set the default font, which program will try to use for rendering, when some kind of font cannot be found in the system, instead of adding a substitution every time we meeting a not-found font.
(Like this? FontConfigs.setDefaultFontName(“Noto Sans CJK Regular”);)

Craig

Hi Craig,

Thank you for writing back.

craig.w.su:
About problem 1, as my understanding, the result can be rendered correctly, If we can find the specific fonts it need for rendering and put them in "/usr/share/fonts" or its subdirectories, right?

Yes, your understanding is correct. Please note, best approach is to acquire all the required fonts and place them in a folder which will be scanned by the Aspose.Cells APIs (or place them in any other folder and set the folder location). Acquiring all the required fonts will ensure that the layout of the document as well as the content's style will remain same in the resultant PDF, images etc. Moreover, the substituted font may not always give you the exact same look and feel as compared to the original document.

craig.w.su:
About problem 2, I know there is no fonts can be used for rendering in all languages, but I want to know that whether there is a method to set the default font, which program will try to use for rendering, when some kind of font cannot be found in the system, instead of adding a substitution every time we meeting a not-found font.
(Like this? FontConfigs.setDefaultFontName("Noto Sans CJK Regular");)

Yes, your understanding is correct for the above case as well. Please note, if a font can't show the text, the API first checks the workbook's default font. If the workbook's default font also cannot show the contents, the API checks and uses the font set for the FontConfigs.DefaultFontName property. Please note, these settings remain active unless you reassign the aforementioned property in your code.