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

Free Support Forum - aspose.com

Aspose.Cells for Java SheetRenderer.toImage generated EMF image quality is not good on Linux

Hi,
XLSX.zip (14.9 KB)

    Workbook book = new Workbook("grid.xlsx");
    System.out.println("Sheet Count: " + book.getWorksheets().getCount());
    Worksheet sheet = book.getWorksheets().get(0);
    sheet.getPageSetup().setPrintArea("A1:C3");
    sheet.getPageSetup().setLeftMargin(0);
    sheet.getPageSetup().setTopMargin(0);
    sheet.getPageSetup().setRightMargin(0);
    sheet.getPageSetup().setBottomMargin(0);
    sheet.getPageSetup().setPrintHeadings(false);
    sheet.getPageSetup().setHeader(1, "");
    //sheet.getPageSetup().setPrintGridlines(true);

    //Define ImageOrPrintOptions
    ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();
    //System.out.println(imgOptions.get);
    imgOptions.setImageFormat(ImageFormat.getEmf());
    imgOptions.setOnePagePerSheet(true);
    imgOptions.setCellAutoFit(true);
    
    SheetRender sr = new SheetRender(sheet, imgOptions);
    sr.toImage(0, "grid.emf");

Thanks

@Muhammed.Karattu,
We have reproduced this issue here and logged it our database for further investigation. You will be notified here once any update is ready for sharing.

This issue is logged as:
CELLSJAVA-43504 - Poor quality EMF generated in Linux

Any update on this issue- CELLSJAVA-43504 - Poor quality EMF generated in Linux ?

@Muhammed.Karattu,

Please make sure that the “Arial” fonts (Both ‘Regular’ and ‘Bold’ style) used in the source file are installed on your linux machine and set by APIs on FontConfigs . e.g. FontConfigs.setFontFolder("Arial Fonts folder path", true);

Yes, this is already tried and didn’t work.

fc-list | grep arial
/usr/share/X11/fonts/TTF/font/arial.ttf: arial
/usr/share/X11/fonts/TTF/font/arialbd.ttf: arialbd
/usr/share/X11/fonts/TTF/font/ariali.ttf: ariali

com.aspose.cells.FontConfigs.setFontFolder("/usr/share/X11/fonts/TTF/font", true);

java -cp ./aspose-cells-21.6.jar:. AsposeImageQuality

@Muhammed.Karattu,

We checked your EMF file (for linux issue) and found it is the missing font issue. Please share more information and details about your environment e.g. System info, JDK info., etc. Also, make sure the fonts in the font folder can be accessed from your program seamlessly, there should not be any rights issue. Moreover, the fonts folder setting line of code, e.g.: “com.aspose.cells.FontConfigs.setFontFolder("/usr/share/X11/fonts/TTF/font", true);” should be pasted at the beginning before Workbook initialization or any other code regarding Aspose.Cells APIs. See the document for your reference:

Furthermore, we also ask you to kindly add a line to your code to save to PDF file format and provide that output PDF file as well. This way we can also confirm which fonts are used in output PDF on your end.

ll /usr/share/X11/fonts/TTF/font
total 4100
-rwxr-xr-x 1 root root 748828 Apr 8 2017 arialbd.ttf
-rwxr-xr-x 1 root root 561731 Apr 8 2017 arialbi.ttf
-rwxr-xr-x 1 root root 555701 Apr 8 2017 ariali.ttf
-rwxr-xr-x 1 root root 178290 Apr 8 2017 ARIALNBI.TTF
-rwxr-xr-x 1 root root 178800 Apr 8 2017 ARIALNB.TTF
-rwxr-xr-x 1 root root 179325 Apr 8 2017 ARIALNI.TTF
-rwxr-xr-x 1 root root 173893 Apr 8 2017 ARIALN.TTF
-rwxr-xr-x 1 root root 778293 Apr 8 2017 arial.ttf
-rwxr-xr-x 1 root root 119809 Apr 8 2017 ariblk.ttf
-rwxr-xr-x 1 root root 155305 Apr 8 2017 verdanab.ttf
-rwxr-xr-x 1 root root 176880 Apr 8 2017 verdanai.ttf
-rwxr-xr-x 1 root root 191220 Apr 8 2017 verdana.ttf
-rwxr-xr-x 1 root root 175351 Apr 8 2017 verdanaz.ttf

java -version
openjdk version “1.8.0_121”
OpenJDK Runtime Environment (build 1.8.0_121-b13)
OpenJDK 64-Bit Server VM (build 25.121-b13, mixed mode)

uname -a
Linux hostname 3.10.0-327.el7.x86_64 #1 SMP Thu Oct 29 17:29:29 EDT 2015 x86_64 x86_64 x86_64 GNU/Linux

PDF generated also attached.

AsposeLinuxCode.PNG (39.0 KB)grid.pdf (17.8 KB)

@Muhammed.Karattu,
Thank you for the feedback. We will analyze it soon.

@Muhammed.Karattu

I have checked your shared pdf file, “Arial” font is not used.

Please run the following code in your program and share us the result.

String fontPath = "/usr/share/X11/fonts/TTF/font/arial.ttf";
File fontFile = new File(fontPath);
byte[] data = Files.readAllBytes(fontFile.toPath());
System.out.println("Font data length: " + data.length);

java.awt.Font font = Font.createFont(Font.TRUETYPE_FONT, fontFile);
System.out.printf("%s,%s,%s\n", font.getFamily(), font.getFontName(), font.getStyle());

Hi,
I tried the code snippet you suggested and it was giving the following Exception.

Exception in thread “main” java.awt.FontFormatException: bad table, tag=1146308935
at sun.font.TrueTypeFont.init(TrueTypeFont.java:564)
at sun.font.TrueTypeFont.(TrueTypeFont.java:198)
at sun.font.TrueTypeFont.(TrueTypeFont.java:178)
at sun.font.SunFontManager.createFont2D(SunFontManager.java:2461)
at java.awt.Font.(Font.java:615)
at java.awt.Font.createFont(Font.java:1056)
at AsposeImageQuality.main(AsposeImageQuality.java:39)

I downloaded arial from from the following url and it’s working fine.

wget https://freefontsdownload.net/download/160187/arial.zip
unzip arial.zip

Font data length: 311636
Arial,Arial,0

EMF file generated this arial font is showing good quality. Screenshot of old vs new is attached here.
Arial-Issue.PNG (41.6 KB)

Thanks a lot for your support in figuring out this issue.

@Muhammed.Karattu,

Good to know that your issue is sorted out by installing the relevant true type font properly. In the event of further queries or issue, feel free to write us back.