Export Sheet Print Area to EMF image with desired size and resolution

Thank you for the response. Will watch this thread closely for any updates.

@oraspose
You are welcome.

@oraspose

Please check the prefix results with setDesiredSize(400, 400, false) and setDesiredSize(400, 400, true) for your reference. Please note, if keepAspectRatio is set to true, the dimension of output EMF can only match desired width or desired height.
prefix_EMF_images.zip (62.9 KB)

@peyton.xu Thanks for trying and providing the sample generated EMF for desired size. It looks good but the EMF image size looks larger when compared to the EMF image generated by ASPOSE.Words library by passing the HTML bytes and saving the document as EMF image.

Is their a way to render the print area of sheet with 72 DPI while exporting as EMF?

I have attached the sample HTML along with Aspose Words generated Word Document and EMF output based on the sample logic provided in this Incorrect Table Layout when saving HTML Table to DOCX and EMF.

Attachment: Sample Table using Aspose Words.zip (35.0 KB)

@oraspose,

Thanks for your feedback with resource files.

We have logged the archive with your existing ticket “CELLSJAVA-45820” into our database. We will look into it and get back to you soon.

1 Like

@oraspose

Please use the following code to get 72 DPI for the generated EMF image.

@oraspose

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.

@oraspose
You are welcome. We will notify you immediately of any 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?

@oraspose,

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.

@oraspose
You are welcome. If you have any questions, please feel free to contact us.

@oraspose

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)

@peyton.xu Thank you for the details.

@oraspose,

You are welcome.

@oraspose,

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.

@oraspose
You are welcome. Once Aspose.Cells v24.2 is released, we will notify you promptly.

The issues you have found earlier (filed as CELLSJAVA-45828,CELLSJAVA-45820) have been fixed in Aspose.Cells for Java 24.2.