Hello Team,
When we insert Chart SVG into a PPT Slide using the below logic programmatically, the underlined text does not render correctly after saving the document as PPTX file. While, when the same SVG is inserted into a PowerPoint Slide using the “Insert Pictures” option, the underlined text gets rendered correctly.
This underline issue occurs only with Slides library while when performing the same usecase with Words library it works fine. We are inserting the SVG into Slide after converting it to EMF image, since inserting SVG image as is generates a PNG image as well within the PowerPoint document which increases the size.
Code used for inserting SVG into PowerPoint slide:
public void insertSvgIntoSlide() {
IPresentation pres = PresentationFactory.getInstance().createPresentation();
try {
Path svgPath = Paths.get("ChartWithUnderLinedText.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("ChartWithUnderLinedText.pptx", SaveFormat.Pptx);
} catch (Exception e) {
throw new IllegalStateException(e);
} finally {
if (pres != null) pres.dispose();
}
}
Code used for inserting SVG into Word Document:
public void insertSvgIntoWord() {
try {
Path svgPath = Paths.get("ChartWithUnderLinedText.svg");
byte[] svgBytes = Files.readAllBytes(svgPath);
String svgContent = new String(svgBytes, StandardCharsets.UTF_8);
HtmlLoadOptions options = new HtmlLoadOptions();
options.setConvertMetafilesToPng(false);
Document document = new Document();
DocumentBuilder builder = new DocumentBuilder(document);
builder.insertImage(svgBytes);
doc.save("ChartWithUnderLinedText.docx");
} catch (Exception e) {
throw new IllegalStateException(e);
}
}
Attachments:ChartWithUnderLinedText.zip (39.8 KB)