Please use the following code to get 72 DPI for the generated EMF image.
For reducing the file size of generated EMF image, we have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): CELLSJAVA-45828
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.
Thank you for logging a ticket for this issue. We will monitor this thread for further updates.
@peyton.xu I used this same logic to generate the EMF with 72 DPI but it looks like the EMF image still shows 96 dpi when previewed using MS Paint tool.
EMF Output: SampleWorkbook.zip (64.7 KB)
DPI validation using Paint tool: SampleWorkbook.png (86.8 KB)
Also, I noticed that the complete print area is not printed in the EMF when below API is used.
imgOpt.setHorizontalResolution(desiredResolution);
imgOpt.setVerticalResolution(desiredResolution);
I think the above API overrides the effect of this API imgOpt.setOnePagePerSheet(true);
on the EMF generation process.
How to overcome this problem?
I did test your scenario/case using the following sample code (as we suggested earlier) with your template XLSX file and you are right. The image is rendered with 96 DPI. We will be looking into it soon.
int desiredResolution = 72;
Workbook wb = new Workbook("f:\\files\\SampleWorkbook.xlsx");
Worksheet sheet = wb.getWorksheets().get(0);
PageSetup pageSetup = sheet.getPageSetup();
pageSetup.setTopMargin(0);
pageSetup.setBottomMargin(0);
pageSetup.setLeftMargin(0);
pageSetup.setRightMargin(0);
String rangeName = "A1:P37";
pageSetup.setPrintArea(rangeName);
ImageOrPrintOptions imgOpt = new ImageOrPrintOptions();
imgOpt.setOnePagePerSheet(true);
imgOpt.setImageType(ImageType.EMF);
imgOpt.setTransparent(true);
imgOpt.setHorizontalResolution(desiredResolution);
imgOpt.setVerticalResolution(desiredResolution);
SheetRender sr = new SheetRender(sheet, imgOpt);
sr.toImage(0, "f:\\files\\output.emf");
output.zip (55.0 KB)
I got the right output EMF image (check the output image) with complete printable area after generating it by the above code segment. I am using latest version of the API (Aspose.Cells for Java v24.1), so you should try it if you are not already using it.
Thanks for trying out. I will try again with the Aspose cells v24.1 from my end.
Using the lastest version v24.1, the resolution of output EMF image is the right value 72. Please check the result EMF image generated by @amjad.sahi .
The resolution in “MS Paint” is the device’s DPI, not the resolution of the EMF image. e.g. you can change display setting in Winodows->Settings of your machine. The resolution in “MS Paint” changes for the same EMF image.(96 for 100% display setting, 192 for 200% setting.)
I use “Microsoft Office Picture”, the resolution is 72.
resolution_72.png (27.4 KB)
This is to inform you that the issue (logged earlier as “CELLSJAVA-45828”) has been resolved. The fix/enhancement will be included in the upcoming release (Aspose.Cells v24.2) that we plan to release in the next week hopefully. You will be notified when the next version is released.
@amjad.sahi Thank you for then notification. Will check this use-case once the 24.02 release is available and confirm if the issue is resolved.
The issues you have found earlier (filed as CELLSJAVA-45828,CELLSJAVA-45820) have been fixed in Aspose.Cells for Java 24.2.
Hello team,
We were able to validate the fix for CELLSJAVA-45828 with ASPOSE CELLS v24.10 and notice that the EMF output size has reduced drastically from 1.22mb to 446kb using the below sample code.
byte[] fileBytes = Files.readAllBytes(Paths.get("SampleWorkbook.xlsx"));
Workbook wb = new WorkBook(fileBytes);
Worksheet sheet = wb.getWorksheets().get(0);
PageSetup pageSetup = sheet.getPageSetup();
pageSetup.setTopMargin(0);
pageSetup.setBottomMargin(0);
pageSetup.setLeftMargin(0);
pageSetup.setRightMargin(0);
pageSetup.setHeaderMargin(0);
pageSetup.setFooterMargin(0);
String rangeName = "A1:P37";
pageSetup.setPrintArea(rangeName);
ImageOrPrintOptions imgOpt = new ImageOrPrintOptions();
imgOpt.setOnePagePerSheet(true);
imgOpt.setImageType(ImageType.EMF);
imgOpt.setTransparent(true);
imgOpt.setHorizontalResolution(72);
imgOpt.setVerticalResolution(72);
imgOpt.setOptimized(true);
SheetRender sr = new SheetRender(sheet, imgOpt);
sr.toImage(0, "SampleWorkbook.emf");
We have the following queries,
- Is it possible to reduce the EMF output size further?
- Does this logic
sr.toImage(0, "SampleWorkbook.emf")
convert the workbook to SVG first and then EMF? Reason for asking is we noticed the EMF output has 72 DPI set(based on above sample code) when previewed using an image viewer but when using ASPOSE WORDS JAVA library to generate the same EMF output we noticed that it does not support resolution because EMF is a vector image.
No, both SVG and EMF are vector images. We convert workbook to EMF directly.
According to MS-EMF specification, we specify the last two properties Device (8 bytes) and Millimeters (8 bytes) that control the horizontal/vertical resolution displayed in some image viewers.
To investigate the possibility to reduce the file size of generated Emf image further, we have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): CELLSJAVA-46183
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.