AnsweredAssumed Answered

Insert Freemarker in MS-Word generated HTML document

Question asked by fhomasp on Apr 21, 2008
Hey,

Perhaps, or to say I hope, someone has tried and succeeded in doing this and can give me some pointers.

Basically I have an XML document in the repository that needs to get its info in a HTML document.  After that it gets transformed to .pdf but that's done through Alfrescos own transformation interface referenced by an inbound content rule.  This last part is not really important for my question unless someone can point me to its relevance.

So I thought I'd just take the Word document and save it as a html file.  A directory gets made with images and an html file which references parts of the image files and xml file list in the folder.

I opened the html file generated and noticed its size, rather biggish.  Obviously I have no clue to what's needed and what's not.  I did remove the document properties in the html file, placed some freemarker syntax below the </head> tag and worked my way down to test three properties.  The code:

<html xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:w="urn:schemas-microsoft-com:office:word"
xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"
xmlns:st1="urn:schemas-microsoft-com:office:smarttags"
xmlns="http://www.w3.org/TR/REC-html40">

<head><title></title>
<meta http-equiv=Content-Type content="text/html; charset=windows-1252">
<meta name=ProgId content=Word.Document>
<meta name=Generator content="Microsoft Word 11">
<meta name=Originator content="Microsoft Word 11">
<link rel=File-List href="images/filelist.xml">
<link rel=Edit-Time-Data href="images/editdata.mso">
<!–[if !mso]>
<style>
v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style>
<![endif]–>

<!— Here are a whole bunch of CSS styles defined –>

</head>
<!– I placed some Freemarker syntax here below this marker –>

<body lang=EN-US link=blue vlink=purple style='tab-interval:36.0pt'>
<#if document.mimetype == "text/xml">
   <#assign dom=document.xmlNodeModel>
       <#list dom.java.object as o>
       <#if o.@class=="data.PersonalData">

<!– From here on the generated stuff continues until I find properties that need inserting.  The freemarker data is found at the bottom of the table, this is one property  –>

<table class=MsoNormalTable border=0 cellspacing=0 cellpadding=0 align=left
style='border-collapse:collapse;mso-table-overlap:never;mso-table-lspace:9.0pt;
margin-left:6.75pt;mso-table-rspace:9.0pt;margin-right:6.75pt;mso-table-anchor-vertical:
paragraph;mso-table-anchor-horizontal:column;mso-table-left:left;mso-table-top:
.05pt;mso-padding-alt:0cm 5.4pt 0cm 5.4pt'>
<tr style='mso-yfti-irow:0;mso-yfti-firstrow:yes;height:19.25pt'>
  <td width=104 style='width:77.7pt;border:solid #667D78 1.0pt;mso-border-alt:
  solid #667D78 .5pt;background:#E2001A;padding:0cm 5.4pt 0cm 5.4pt;height:
  19.25pt'>
  <p class=MsoNormal style='mso-element:frame;mso-element-frame-hspace:9.0pt;
  mso-element-wrap:around;mso-element-anchor-vertical:paragraph;mso-element-anchor-horizontal:
  column;mso-element-top:.05pt;mso-height-rule:exactly'><span lang=EN-GB
  style='mso-ansi-language:EN-GB'>First Name:<o:p></o:p></span></p>
  </td>
  <td width=253 style='width:189.7pt;border:solid #667D78 1.0pt;border-left:
  none;mso-border-left-alt:solid #667D78 .5pt;mso-border-alt:solid #667D78 .5pt;
  padding:0cm 5.4pt 0cm 5.4pt;height:19.25pt'>
  <p class=MsoNormal style='margin-top:3.0pt;margin-right:0cm;margin-bottom:
  3.0pt;margin-left:0cm;mso-element:frame;mso-element-frame-hspace:9.0pt;
  mso-element-wrap:around;mso-element-anchor-vertical:paragraph;mso-element-anchor-horizontal:
  column;mso-element-top:.05pt;mso-height-rule:exactly'><span lang=EN-GB
  style='color:gray;mso-ansi-language:EN-GB'>
             <#list o.void as v>
                <#if v.@property=="firstName">
                    ${v.string}
                </#if>
            </#list>
<o:p></o:p></span></p>
  </td>
</tr>

<!– I tried two more properties but its the same thing as above, pretty much.  I then ended with finding the </body> tag and wrote the next freemarker stuff above it.

<#else>
    No XML file
</#if>
</body>

</html>


So obviously between the <#if> tag and </#if> tag defining the freemarker stuff there is a whole lot of html-like code to be found.

I opted for MS Word to do the transformation between .doc and html as OpenOffice writer couldn't save much of the layout.  But perhaps I should just try with the openoffice stuff as it's 100 times smaller with cleaner html code.

But if anyone who has ever done this kind of thing before can tell me how to do all that and save the layout It'd be greatly appreciated.


Thanks,
fhomasp

Outcomes