misc_bb 7 Posted August 11, 2021 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 Posted August 12, 2021 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
misc_bb 7 Posted August 12, 2021 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 Posted August 13, 2021 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
misc_bb 7 Posted October 6, 2021 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? Share this post Link to post
Guest Posted October 7, 2021 (edited) @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 October 7, 2021 by Guest Share this post Link to post
Lars Fosdal 1792 Posted October 7, 2021 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 Posted October 7, 2021 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
misc_bb 7 Posted October 8, 2021 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