Discussion:
SVG image support in XSLF
Ritesh Sood
2018-05-06 08:33:51 UTC
Permalink
Office 365 has added support for SVG images. This is very useful to me as I
need to create slidedecks with ~100 slides with plots of simulation data.
Its highly desirable to have vector graphics. The simulation data is
generated on linux where I can produce eps, or svg files. XSLF has support
of eps, but images embedded in this format do not display when the pptx is
viewed in Windows. So svg is the only remaining option.

I have modified the POI source and could get it to copy the .svg file to
the ppt/media folder and add an entry in the corresponding
ppt/slides/_rels/slideX.xml.rels. However the following issue remains: When
Powerpoint adds a svg file the following appears in slide.xml:
<code>
<p:blipFill>
<a:blip r:embed="rId2">
<a:extLst>
<a:ext uri="{28A0092B-C50C-407E-A947-70E740481C1C}">
<a14:useLocalDpi val="0" xmlns:a14="
http://schemas.microsoft.com/office/drawing/2010/main"/>
</a:ext>
<a:ext uri="{96DAC541-7B7A-43D3-8B79-37D633B846F1}">
<asvg:svgBlip r:embed="rId3" xmlns:asvg="
http://schemas.microsoft.com/office/drawing/2016/SVG/main"/>
</a:ext>
</a:extLst>
</a:blip>
<a:stretch>
<a:fillRect/>
</a:stretch>
</p:blipFill>
</code>
But with my modified POI, this is what I see:
<code>
<p:blipFill>
<a:blip r:embed="rId2"/>
<a:stretch>
<a:fillRect/>
</a:stretch>
</code>
In particular, we need to include the svgBlip element for this to work
http://interoperability.blob.core.windows.net/files/MS-ODRAWXML/[MS-ODRAWXML].pdf
Also a png copy of the svg needs to be generated (rId2 in the Powerpoint
generated code is png, and rId3 is the svg.

Help is getting this done is highly appreciated!

Thanks,
Ritesh
Andreas Beeker
2018-05-06 10:02:06 UTC
Permalink
Hi Ritesh,

generating the png thumbnails should be possible with Batik [1].

Adding those extension elements should be possible via the XSLFShape.getXmlObject() method.
If the xmlschema doesn't provide you with the accessors, you need to use a XmlCursor [2]
to add the elements.

When using those features, Office usually uses AlternateContent elements, to provide additionally
a fallback structure. You don't need to provide the AlternateContent wrapper but insert
either the choice or fallback element directly.

If you intend to read and then modify files (template approach), please make sure to use a trunk version of POI,
as I've included an additional schema for handling AlternateContents ... otherwise those
elements are ignored (... sometimes).

Andi


[1] https://xmlgraphics.apache.org/batik/
[2] https://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFObjectShape.java?view=markup#l281
Ritesh Sood
2018-05-07 03:30:03 UTC
Permalink
Hi Andi,

thanks for your input. I have looked at the code you've pointed to for
including extension elements. However, given my limited fluency with
xml/xsd, and even java, I really couldn't figure out how to go about this.
I earlier breakpointed at
https://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java?view=markup#l76
and seemed to me that that's where change needed to be made. Not sure how
to incorporate the XSLFShape.getXmlObject() method that you pointed to.

Looks like I'll have to put in a feature request for this and wait.

Thanks,
Ritesh
Post by Andreas Beeker
Hi Ritesh,
generating the png thumbnails should be possible with Batik [1].
Adding those extension elements should be possible via the
XSLFShape.getXmlObject() method.
If the xmlschema doesn't provide you with the accessors, you need to use a XmlCursor [2]
to add the elements.
When using those features, Office usually uses AlternateContent elements,
to provide additionally
a fallback structure. You don't need to provide the AlternateContent wrapper but insert
either the choice or fallback element directly.
If you intend to read and then modify files (template approach), please
make sure to use a trunk version of POI,
as I've included an additional schema for handling AlternateContents ... otherwise those
elements are ignored (... sometimes).
Andi
[1] https://xmlgraphics.apache.org/batik/
[2]
https://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFObjectShape.java?view=markup#l281
Ritesh Sood
2018-05-13 07:56:41 UTC
Permalink
Hi Andi,

By a remarkable feat of (reverse) engineering, I was able to modify the
code so that I'm able to include SVG images in the .pptx. A PNG version of
the image is also created using Batik and included in the slidedeck. I've
verified the output on Windows where the SVG is displayed, and on linux and
MacOS where the PNG is displayed. The code I've added is really a hack and
is far from production quality. I'll add a patch to bugzilla just in case
its useful to someone doing real development on this feature.

Thanks!
Ritesh
Post by Ritesh Sood
Hi Andi,
created a bug report and attached a simple program to add figure slides
https://bz.apache.org/bugzilla/show_bug.cgi?id=62365
Thanks,
Ritesh
Post by Andreas Beeker
Hi Ritesh,
I only have an Office 365 installation at work - please provide a sample
file.
You can e.g. upload it to a bugzilla entry.
Andi
Loading...