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

Free Support Forum - aspose.com

Chart to Image is not working properly in Linux environment

Hello,


I found another issue with some chinese characters. They are showing as junk characters in emf file. Please find attached sheet.xlsx and Generated Emfs.zip.

Note: Things are working fine with windows environment, but not with any Linux environment.

In my font directory, I put extracted calibri.zip (all ttf files).

Sample Code:

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;

import com.aspose.cells.CellsHelper;
import com.aspose.cells.Workbook;
import com.aspose.slides.License;

public class OLEMigration {

public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
License l = new License();
l.setLicense(“Aspose.Slides.lic”);
com.aspose.cells.License l1 = new com.aspose.cells.License();
l1.setLicense(“Aspose.Cells.lic”);
Run();
}

public static void Run() throws Exception {
// Create a workbook
CellsHelper.setFontDir("/home/vagrant/Desktop/Fonts");
File file = new File(
“/home/vagrant/Desktop/sheet.xlsx”);
int length = (int) file.length();
FileInputStream fstro = new FileInputStream(file);
byte[] buf = new byte[length];
fstro.read(buf, 0, length);
fstro.close();

Workbook wb = new Workbook(new ByteArrayInputStream(buf));

com.aspose.cells.ImageOrPrintOptions opts = new com.aspose.cells.ImageOrPrintOptions();

opts.setImageFormat(com.aspose.cells.ImageFormat.getEmf());
ByteArrayOutputStream imageStream = new ByteArrayOutputStream();
wb.getWorksheets().get(“Chart”).getCharts().get(0).toImage(imageStream, opts);

FileOutputStream f = new FileOutputStream(new File("/home/vagrant/Desktop/test.emf"));
imageStream.writeTo(f);
f.close();
}

}

Hi Dipen,


Thank you for contacting Aspose support.

First of all, please note that we have split your existing thread to create a new one on your behalf as it is appropriate to post all distinct problems in separate threads for better visibility.

Regarding your original concerns, I have checked the two EMF files and have compared them side by side. I am afraid, I am not able to notice any junk characters as mentioned in your post. However, there is slight change in the font size across two images. I have attached the comparison here as well. Could you please highlight the characters as mentioned in your post? Moreover, please provide the PDF files generated on Windows as well as Linux by using Chart.toPdf method while using latest release Aspose.Cells for Java 8.7.1.2 (attached). This will help us identify any problem related to font substitution.

Hi Babar,


You are using IrfanView, that is why you don’t find any junk character. If you use any standard windows image tool (i.e. Paint/Microsoft Office Picture Manager), then you can find those junk characters. See my comparision.png.

For PDF, it is working fine. Actually we are embedding emf file in powerpoint, so it is very critical issue for us. See the attached pptx file with embedded ole object. If emf file doesn’t show junk characters in paint/Microsoft Office Picture Manager, then junk characters won’t show in powerpoint too.

Thanks,
Dipen Sompura.

Hi Dipen,


Thank you for sharing more details.

You are right, when I viewed the resultant EMF files in Microsoft Paint application, I can see the said issue. I have logged this incident in our bug tracking system as CELLSJAVA-41770 for further investigation by the product team. Please spare us little time to properly analyze the scenario and get back with updates in this regard.

Hi Dipen,


Thank you for your patience with us.

We have looked into the matter logged earlier as CELLSJAVA-41770 and we have concluded the problem cause to be the missing font required to render the Asian characters in resultant EMF. You can solve the problem by placing the MS Arial Unicode font’s TTF (or any font capable of rendering the Asian characters) along with Calibri TTFs in a folder and set the directory location using the System.setProperty(“Aspose.Cells.FontDirExc”, fontDir) at the start of your application. This way, you are restricting the Aspose.Cells for Java API to use the fonts available in the specified directory only, whereas Linux’s default font directories will be skipped. I have attached the resultant EMF generated with above mentioned approach.

Thanks, Now it is working fine.

Hi Dipen,


Thank you for the confirmation. It is good to know that you are up & running again. Please feel free to contact us back in case you need our further assistance with Aspose APIs.