Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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> 
like image 979
Saul Avatar asked Aug 11 '10 07:08

Saul


People also ask

How to add page numbers later in word?

If all page numbers are deleted, go to Insert > Header & Footer and select Other Pages on the left side,. Go to Insert > Page Number and choose a number placement.

How to change Start Page Number in word?

To choose a format or to control the starting number, go to Header & Footer > Page Number > Format Page Numbers. To change the numbering style, select a different style in Number format. To change the starting page number of the newly created section, select Start at, and then enter a number. Select OK.

How to make the second Page Number 1 in word?

At the bottom of the window, select Start at:, and then select the number just below what you want your first page number to be (e.g., if you want the page after the title page to be page 1, select 0 as the starting page number). Click OK twice to return to Word.


2 Answers

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!

like image 137
Selcuk Sasoglu Avatar answered Nov 08 '22 15:11

Selcuk Sasoglu


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>
like image 31
Henry Avatar answered Nov 08 '22 14:11

Henry