Hello team.
We encountered an issue when converting a given SVG image to EMF and inserting into empty PPT document.
The sample code for conversion is as following:
private static byte[] convertSvgImageToEmf(byte[] imagebytes, IPresentation pptx) {
ISvgImage svgImage = new SvgImage(imagebytes);
IPPImage tmpImage = pptx.getImages().addImage(svgImage);
return tmpImage.getBinaryData();
}
The data labels in the input SVG are aligned vertically with the legend colors. However, after converting to EMF and inserting into PPT document, the text in the labels is misaligned vertically compare to the colors.
Attached is archive that contains the following:
- regularBarChart.svg - input bar chart in SVG format ;
- EmptyRegularDoc.pptx - empty PowerPoint presentation;
- regularBarChart.svg_26.2.pptx - Presentation after SVG image converted into EMF and inserted;
- SvgImageLegendLabels.java - small sample code to reproduce the issue.
Please let us know if you need more information.
Thank you.
SvgToEmfLabels.zip (100.9 KB)
@oraspose
Thanks for the sample file(s); that should help with reproduction. I have not confirmed this yet and can only confirm it after reproducing on our side. Based on your description, this might be a bug in Aspose.Slides when converting svg to emf. To confirm and log it internally, I need a few details.
- Which Aspose.Slides for Java version are you using (including build number)?
- What Java runtime (version/vendor) and operating system are you running the conversion on?
- After obtaining the EMF bytes, how are you adding the image to the PowerPoint slide (e.g., addPictureFrame, scaling options, etc.)?
A support engineer will review your answers and follow up in this thread.
I’ll try to reproduce this using your samples. If I can confirm it, I’ll log it internally and follow up here.
A support engineer will follow up in this thread if needed.
Aspose.Slides version used is the latest - 26.2.0
Environment details:
- java full version: 1.8.0_471-b09
- OS - Oracle Linux 8 Oracle Linux 8 version 8.10 ; same on Windows 11 Pro
Image EMF (imagebytes) is added to the PowerPoint presentation via : IPPImage imgx = pptx.getImages().addImage(imagebytes); and IPictureFrame pf = islide.getShapes().addPictureFrame() . See attached archive for sample reproducible code.
@oraspose,
Thank you for contacting free support. Unfortunately, I was unable to see any difference between the source SVG image and the image in the output presentation file.
compare.png (178.0 KB)
Could you please check the issue again carefully and point out what is wrong on the screenshot?
The difference would be clear if you open the SVG image not in the browser, but in a different viewer - for instance , SVG Explorer or GIMP 2.10. See attached comparisons.
Thank you.
SVG_vg_EMF_in_PPTSlide.png (68.0 KB)
InputSVG_labels_aligned_in_GIMP.png (105.6 KB)
@oraspose,
Thank you for the additional information. I need some time to investigate the issue. I will get back to you as soon as possible.
@oraspose,
I have reproduced the problem where the legend labels are not positioned correctly when converting the image from SVG to EMF and adding it to the slide.
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): SLIDESJAVA-39780
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.
@oraspose,
The main problem with the placement of the text is caused by the use of the dominant-baseline attribute (by the way, the x-axis labels are also offset). This attribute is interpreted differently by browsers and editors. Therefore, in Chrome and Mozilla, this SVG file is displayed with the text shifted. In the browser, this attribute is applied not just to the text block (as happens in editors), but also based on the font metrics.
To fix this problem in this particular example, we recommend using the auto value for this attribute.
Code example:
Presentation pptx = new Presentation("EmptyRegularDoc.pptx");
ISlide slide = pptx.getSlides().get_Item(0);
byte[] imageBytes = Files.readAllBytes(Paths.get("regularBarChart.svg"));
String svgContent = new String(imageBytes, StandardCharsets.UTF_8).replaceAll(
"dominant-baseline=\"text-before-edge\"", "dominant-baseline=\"auto\"");
imageBytes = convertSvgImageToEmf(svgContent.getBytes(), pptx);
final IPPImage image = pptx.getImages().addImage(imageBytes);
slide.getShapes().addPictureFrame(
ShapeType.Rectangle, 10, 20, image.getWidth(), image.getHeight(), image);
pptx.save("output.pptx", SaveFormat.Pptx);
pptx.dispose();
static byte[] convertSvgImageToEmf(byte[] imagebytes, IPresentation pptx) {
ISvgImage svgImage = new SvgImage(imagebytes);
IPPImage tmpImage = pptx.getImages().addImage(svgImage);
return tmpImage.getBinaryData();
}
The result: output.zip (63.0 KB)