Creating a Word document in Coldfusion - how to have pagenumbering?
Asked Answered
C

2

9

I am creating a Word format .doc using the following code, then cfheader and cfcontent to serve. All is good but I need to be able to place dynamic information in the header (or footer), or automatic pagenumbering would be a second best option.

How should I modify the code?

<cfsavecontent variable="myDocument">
<html xmlns:w="urn:schemas-microsoft-com:office:word">
<!--- Head tag instructs Word to start up a certain way, specifically in
print view. --->
    <head>
        <xml>
         <w:WordDocument>
            <w:View>Print</w:View>
            <w:SpellingState>Clean</w:SpellingState>
            <w:GrammarState>Clean</w:GrammarState>
            <w:Compatibility>
             <w:BreakWrappedTables/>
             <w:SnapToGridInCell/>
             <w:WrapTextWithPunct/>
             <w:UseAsianBreakRules/>
            </w:Compatibility>
            <w:DoNotOptimizeForBrowser/>
         </w:WordDocument>
        </xml>
    </head>
<body>
    Regular HTML document goes here
    <!--- Create a page break microsoft style (took hours to find this) 
--->
    <br clear="all"
style="page-break-before:always;mso-break-type:page-break" />
    Next page goes here
</body>
</html>
</cfsavecontent> 
Chalybite answered 11/8, 2010 at 7:59 Comment(1)
version 9.01, have to add minimum text to be allowed to commentChalybite
F
4

Please have a look at this: Header & Footer I have successfully created custom header and footer with only one html file using this article. (Word 2003)

Hope this helps!

Finder answered 17/8, 2010 at 14:40 Comment(1)
Using your method, is there a way to omit the first page of the page number and start it on the second page?Lawrenson
M
1

Doesn't seem easy to add page number using a WordprocessingML

http://openxmldeveloper.org/archive/2006/08/03/443.aspx

If you can serve PDF instead of DOC, here's a solution for page numbering.

http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7c21.html

See example 2:

<cfdocument format="pdf"> 
<cfdocumentitem type="header" evalatprint="true"> 
    <table width="100%" border="0" cellpadding="0" cellspacing="0"> 
        <tr><td align="right"><cfoutput>#cfdocument.currentsectionpagenumber# of 
            #cfdocument.totalsectionpagecount#</cfoutput></td></tr> 
    </table> 
</cfdocumentitem> 

<cfdocumentitem type="footer" evalatprint="true"> 
    <table width="100%" border="0" cellpadding="0" cellspacing="0"> 
        <tr><td align="center"><cfoutput>#cfdocument.currentpagenumber# of 
            #cfdocument.totalpagecount#</cfoutput></td></tr> 
    </table> 
</cfdocumentitem> 

...    

</cfdocument>
Madian answered 11/8, 2010 at 19:27 Comment(1)
Useful link thanks Henry, the client needs it to be .doc or .rtf though.Chalybite

© 2022 - 2024 — McMap. All rights reserved.