Hello Team,
We are using ASPOSE WORDS Java v24.2 to convert TABLE into EMF output using the below sample code.
byte[] htmlBytes = Files.readAllBytes("SampleTable.html");
HtmlLoadOptions options = new HtmlLoadOptions();
options.setConvertMetafilesToPng(false);
options.setEncoding(StandardCharsets.UTF_8);
Document doc = new Document(htmlBytes, options);
DocumentBuilder builder = new DocumentBuilder(doc);
PageSetup pageSetup = builder.getPageSetup();
double margin = 0;
pageSetup.setLeftMargin(margin);
pageSetup.setRightMargin(margin);
pageSetup.setTopMargin(margin);
pageSetup.setBottomMargin(margin);
pageSetup.setHeaderDistance(margin);
pageSetup.setFooterDistance(margin);
pageSetup.setPaperSize(PaperSize.CUSTOM);
pageSetup.setPageWidth(1150);
pageSetup.setPageHeight(695);
Section section = doc.getFirstSection();
Body body = section.getBody();
TableCollection tables = body.getTables();
if (tables.getCount() == 1) {
Table table = tables.get(0);
table.setLeftIndent(0);
table.autoFit(AutoFitBehavior.AUTO_FIT_TO_WINDOW);
... // other table row and cell layout settings are performed
}
// Save as EMF format
ImageSaveOptions emfOptions = new ImageSaveOptions(SaveFormat.EMF);
emfOptions.setPageSet(new PageSet(0));
emfOptions.setResolution(72f);
emfOptions.setTransparent(true);
emfOptions.setPaperColor(new Color(255, 255, 255, 0));
emfOptions.setOptimized(true);
doc.save("Test.emf", emfOptions);
We have few queries regarding the EMF output using the above code.
- How do I validate the DPI of the EMF image set using this method
emfOptions.setResolution(72f)
? Because, when I open the image using MS Paint tool it always shows DPI as 96. - Whether I use this method
emfOptions.setOptimized(true);
or not, the EMF output size remains the same which is 240Kb(approx.)? Does this method have any effect on vector images such as EMF? If yes, then how do I optimize the EMF image further more to obtain a more reduced size? I do not have a number but would like to know to what extent I can reduce the EMF size further.
SampleTable.zip (2.9 KB)