infopath to word, images issue

hey all,
i have been trying to solve this problem for a while now.
i have made an infopath form with repeating sections, repeating tables, and images.
i am using C# to export it to a word dosument template of which i extracted the document.xml part and created from it a XSLT sheet to do the transformation.
the only issue i am facing, which i still cannot solve is the fact that i can't use the XSLT to import the images to the word template!
does anyone know a way to do that?
i would be greatful for ur help
thank you
jadhamAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

abelCommented:
I'm not really sure what you are asking here, but XSLT cannot be used to do anything with images, other then moving the links to the images around. That is, because XSLT is meant for manipulating XML text data, and cannot be used to manipulate (not even pass-through) binary data.
0
abelCommented:
(and images are binary data)
0
jadhamAuthor Commented:
hey abel, thank u for ur comments, i really hope u can help me with this issue.
in the xml form the images are stored encoded base64, what i am investigating is whether there is a way to decode the images via the xslt to make them fall in the right place in the word document.
now what u made me realize is that if i insert the images as links in the form rather than importing the image itself i might be able to put them in the right place in the word document template.
can u help with that?
thanks in advance,
regards
0
Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

jadhamAuthor Commented:
i dunno if this would help:
      <my:group9>
            <my:group10>
                  <my:field36>file://C:\Users\TESTADMIN\Pictures\DSC00047.JPG</my:field36>
            </my:group10>
the xml form regarding the image is that.
how should i do the xslt so that it gets imported to word. (i am using office 2007 if this would help!)
please bare with me, i am new to the xml/xsl  world
thanks
0
jadhamAuthor Commented:
it's a repeating group btw
0
abelCommented:
The output you are generating with XSLT, is that WordML?

I can help you with the XSLt / XML bit, but I am not sure how to make an external link to a file in a WordML document. It is not possible to put the binary data in there, but WordML is XML and XML does not allow binary data (for the same reason that XSLT does not allow it, because that too is XML).

You say that you have a way to get the Base64 data of the image. That would make it workable (still, do not expect that any XML technology can convert that in to a real binary JPG) and I assume that WordML, if that's indeed your target, uses a base64 version.
0
jadhamAuthor Commented:
i just found a link hoping to know what to do with it!
http://www.tkachenko.com/blog/archives/000106.html
maybe u could get a clearer view at it, i also found another link
http://www.infopathdev.com/forums/p/2294/9428.aspx#9428
but also i still can't make the connection with my form!
this thing is devastating!
0
abelCommented:
That's a good first link. I shows a method of using scripting to get an external file as base64 bytes and then to store it in the WordML. So you are indeed using WordML, good, and you can indeed use base64. The example shown there uses C# to do so. Would that be an approach you can take? Do you use XslCompiledTransform or similar?

It is 2.20AM here, so I'm off for now. Let me know whether you can make the code oa tkachenko working, otherwise, I'll try my hands on it tomorrow.
0
jadhamAuthor Commented:
In fact the application that i am making to automate the form transformation to word is in C#.
I am using WordML, and an XSLCompiledTransform.
I managed to clear all the loose ends, but still this last thing of inserting the images i want into the word document!!
When i save the form the xml document produced is all similar to:
     <my:group9>
            <my:group10>
                  <my:field36>.......base64 image data........</my:field36>
            </my:group10>

</my:group9>
nothing is more detailed.
the first link showed that other than the script, the part of the XSLT sheet responsible to get the image data is:
<w:pict>
        <w:binData w:name="{$url}">
          <xsl:value-of select="ext:EncodeBase64(@src)"/>
        </w:binData>
        <v:shape id="{generate-id()}" style="width:100%;height:auto">
          <v:imagedata src="{$url}" o:title="{@alt}"/>
        </v:shape>
      </w:pict>

but how can i integrate my fields with that?
good night and thanks for your help!
0
jadhamAuthor Commented:
dear abel,
u still can't help me with that?
regards
0
abelCommented:
apologies, missed the followup, I'll check. Will be in a couple of hours though, but i'll be back...
0
jadhamAuthor Commented:
forgot me again?
am sorry for nagging i just wanna end up with this thing!!
0
abelCommented:
Yes, apparently I did. It is all so busy here that the voluntary work is left behind a bit, apologies for that, again...

Looking over your provided information and the link, it seems that you indeed got most part going. From what you are writing, I'm unsure whether you got the extension function working or not for getting the binary external source into the base64 encoding. The part that does that is copied in the code snippet section. Make sure to bind the ext-prefix to some namespace.

Then, the @src attribute you have above inside the ext:EncodeBase64 function should point to an element or attribute inside your source that actually is the image. For testing purposes, I suggest you just hard-code this as a local path.

I assume you understood the part on that link about creating the correct $url (the variable template is on that page, you can reuse that). The alt attribute is less important (but put some text there, just remove the AVT for the moment with some literal text).

-- Abel --

  <msxsl:script language="C#" implements-prefix="ext">
  public static string EncodeBase64(string file) {
    System.IO.FileInfo fi = new System.IO.FileInfo(file);
    if (!fi.Exists)
      return String.Empty;
    using (System.IO.FileStream fs = System.IO.File.OpenRead(file)) {
      System.IO.BinaryReader br = new System.IO.BinaryReader(fs);
      return Convert.ToBase64String(br.ReadBytes((int)fi.Length));
    }
  }
  </msxsl:script>

Open in new window

0
jadhamAuthor Commented:
hey again!
i have to bother u again am sorry for that!and excuse me i have to ask u something since i am still new to this site!what do u mean by voluntary work? if i give points you don't get them?!:S my trial finished but due to the amazing info available on this site i paid for a membership!
in the attached code snippet i've put the elements that would be related to the pics, i hope that i understood exactly what to do, my problem is that using C# i have to enable script using so i couldn't test it.
when i try to run the program, after filling out the form and press the convert button, it throws me an excpetion that i have to enable scripts from C# so that they can be run when the transformation happens!

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2009-05-09T08:19:57" xmlns:xd="http://schemas.microsoft.com/office/infopath/2003" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ve="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" 
xmlns:ext="my_extension">
<xsl:output method="xml" />
<msxsl:script language="C#" implements-prefix="ext">
  public static string EncodeBase64(string file) {
    System.IO.FileInfo fi = new System.IO.FileInfo(file);
    if (!fi.Exists)
      return String.Empty;
    using (System.IO.FileStream fs = System.IO.File.OpenRead(file)) {
      System.IO.BinaryReader br = new System.IO.BinaryReader(fs);
      return Convert.ToBase64String(br.ReadBytes((int)fi.Length));
    }
  }
  </msxsl:script>
<xsl:template match="/">
 
......
......
 
<w:p w:rsidR="00E90254" w:rsidRDefault="00E90254" w:rsidP="00E90254"><w:pPr><w:jc w:val="center"/><w:rPr><w:b/><w:sz w:val="28"/><w:szCs w:val="28"/></w:rPr></w:pPr><w:r><w:rPr><w:b/><w:sz w:val="28"/><w:szCs w:val="28"/></w:rPr><w:r>
    <w:pict>
        <w:binData w:name="file://C:\Users\TESTADMIN\Pictures\DSC00047.JPG">
          <xsl:value-of select="ext:EncodeBase64(@src)"/>
        </w:binData>
        <v:shape id="{generate-id()}" style="width:100%;height:auto">
          <v:imagedata src="file://C:\Users\TESTADMIN\Pictures\DSC00047.JPG" o:title="test"/>
        </v:shape>
      </w:pict>
 
</w:r></w:p>
 
.........

Open in new window

0
abelCommented:
What I mean is that all experts at experts exchange are volunteers. The points system is merely for a certain ranking and has nothing to do with money in any kind. As such, we can only be around on the days and times that our free time allows. The main reason most of us do this is exchange of expertise (learning / teaching experiences), ranking (good some people's résumé's) or just for the fun of it.


> when i try to run the program, after filling out the form and press the convert button,
> it throws me an excpetion that i have to enable scripts from C#
not sure what program you use for running the code, but the exception is correct in that you should enable scripting. Assuming you have a C# program that runs your XSLT you can use the following line to enable scripting:

// enable xsl document() function and msxml scripting
XsltSettings xsltSettings = new XsltSettings(true, true);
 
// load xslt w/debug (you can use false as well if you don't want to debug)
XslCompiledTransform xslt = new XslCompiledTransform(true);
xslt.Load("your.xslt", xsltSettings, null);

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
abelCommented:
While it's been a while (a year ago), I'd like to recommend this question be closed differently. The original error and problems the user had were taken away. New errors appeared and I provided a solution for that too. The user indicated that the he uses C# (which I missed), and I provided a working C# example to get his code going. The example is applicable to more than this scenario only.

So, in short, I recommend this question be closed by accepting http:#24613959 as an answer (more answers can be found in the thread, but this one is more worthwhile for later readers).
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.