Hello Team,
We add SVG based chart as EMF image into PPT Slide after converting the SVG to EMF bytes using the logic mentioned here getBinaryData Method Seems To Do the SVG to EMF Conversion in Java.
Issue: The SVG chart when previewed in browser does render the label vertically center aligned while the EMF image that was converted from SVG using Slides JAVA does not render it vertically center aligned.
Code used for SVG to EMF conversion:
public void convertSvgToEmfUsingSlides() {
IPresentation pres = PresentationFactory.getInstance().createPresentation();
try {
Path svgPath = Paths.get("CircularChart.svg");
byte[] svgBytes = Files.readAllBytes(svgPath);
String svgContent = new String(svgBytes, StandardCharsets.UTF_8);
// Add SVG image to temp slide and extract EMF binary data from it
IPresentation tempPres = PresentationFactory.getInstance().createPresentation();
ISvgImage svgImage = new SvgImage(svgContent);
IPPImage emfImage = tempPres.getImages().addImage(svgImage);
byte[] emfBytes = emfImage.getBinaryData();
// Now, add the extracted EMF bytes to original slide
ISlideCollection slides = pres.getSlides();
IPPImage ppImage = pres.getImages().addImage(emfBytes);
slides.get_Item(0).getShapes().addPictureFrame(ShapeType.Rectangle, 0, 0,
ppImage.getWidth(), ppImage.getHeight(), ppImage);
pres.save("CircularChart.pptx", SaveFormat.Pptx);
} catch (Exception e) {
throw new IllegalStateException(e);
} finally {
if (pres != null) pres.dispose();
}
}
Attached Original SVG, Converted EMF and PPTX files for reference. CircularChart.zip (82.7 KB)
OS: Oracle Linux 7 (x86-64) UEK Release 4
java full version “1.8.0_331-b09”