Jump to content
misc_bb

Working with SVG in OpenXML SDK in Delphi

Recommended Posts

Currently working on generating a docx file with an SVG image insertion. I have followed along this blog utilizing OpenXML byBruno Sonnino. I notice that if the image are non-svg (jpg, png, etc) they are embedded as is but if you insert SVG image it will create a second file that is in .png format. This part is somehow tricky for me. Not sure how to it can be done. Has anyone tried this before? When is the process generating .png happen?

 

Thanks!

Share this post


Link to post
Guest

I am not 100% sure about the reference to the blog, but it seems like it is a set of examples of how to manipulate OOXML files.

I would guess that the samples do not contain a specific routine for what you are trying to do.

So what i used to do is read the specs, let word do it (whatever complex operation) and analyse the resulting file from word, then mimic the "actions" needed for a complete "operation".

There's also the Microsoft SDK tools to inspect files rather than unpacking and sifting through the archive with EditPad or VS.

The SDK tool exposes the some C# classes and i would guess (have not checked, not interested in having a .net dll in my server setups) they have some functionality, but that is .NET and i am 100% Delphi, so zip + xml it is for me.

 

HTH

 

I should say that i started to exchange my own ooxml code with delphihtmlcomponents office library, one reason is that i hate writing image manipulation routines 🙂

Share this post


Link to post

Yeah this is a bit of a pain. We have our existing implementation with Open Office/Libre Office and it works fine but we want to support SVG in our document generator this time. Just going thru with the SDK alone is already tedious. I would love to utilized a component or office library for this one but even the libraries like Axolot does not support SVG. I would love try your approach but for now one of my requirements is to generate a document file then a PDF as well. I don't want to have a .net dll as well but we'll see how this goes. 

 

Thanks a lot!

Share this post


Link to post
Guest

misc_bb, delphihtmllibrary has an "office" add-on. It is almost as pricey as the .net variants out there. I have incorporated it now at around 40% for my own imlementations. Comes with image handling classes too. Generally, it looks great. You should IMHO send an e-mail to them for a quote or more info. Pure delphi code, no external libs, so quite unique actually.

Share this post


Link to post

I've been working with Delphi and OOXML for a few weeks now and although its a bit tedious setting everything but generating simple documents is becoming handy. This has been my starting guide: https://blogs.msmvps.com/bsonnino/2021/05/15/creating-openxml-files-with-delphi/?unapproved=5149&moderation-hash=435cc9a4d4ae1108be452c23b773f04f#comment-5149

Thanks to Sir Bruno!

 

The only problem I cannot figure out is this prompt when opening the docx file generated from Delphi, see attached image. I'm not exactly sure if I can get rid of it but I would like to know if anyone else working with OOXML in Delphi if you have encountered the same? 

 

 

docxprompt.png

Share this post


Link to post
Guest

@misc_bb, i had that too. I had to switch XML libraries in the end. I do not recall exactly what was the problem, something about a line-break after the first or second row of the XML.

When word reads the unzipped XML's it is very very picky.

Create an almost empty doc both with your code and with word. Then use BeyondCompare or VC to check all differences. After a while you will have rooted them out.

If you do not get anywhere i could scan my old code for comments but that may prove a rather lengthy operation 🙂

(You will have use for Microsofts Open XML Productivity Tool 2.5).

Edited by Guest

Share this post


Link to post

Have you tried using an XML lint tool or validator to check the integrity of the XML file?

The MS Word Error is inconclusive to whether it is a structural error, character set error, or logical error in the XML.

Share this post


Link to post
Guest

AFAIR, check the written [Content_Types].xml for extra spaces, cr/lf not exactly matching.

IIRC i compared byte-wise in EditPad and changed to Kluug XML that could write exactly like that.

But it was a long time ago...

Share this post


Link to post

I haven't tried the integrity check of the XML file although I do check/compare them in VC with those generated by Word itself but I'll try your suggestions. Thanks! 🙂

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×