Transcript Document

Serving Word
Serving Word
Using HTML, XML, and CSS to
Dynamically Generate Word Documents
Samuel R. Neff
B-Line Express
September 18, 2002
Samuel R. Neff
Serving Word
Agenda
• Automation
• Document Properties
• HTML, XML, CSS
–
–
–
–
–
Formatting
Labels
Columns
Headers, Footers
Images
• Alternatives
September 18, 2002
Samuel R. Neff
Serving Word
Automation
•
•
•
•
Control one application from another
Use COM object “Word.Application”
Complete flexibility and power
Limitations
– Unattended execution
– Slow
– CF COM Support (all versions)
September 18, 2002
Samuel R. Neff
Serving Word
Document Properties
•
•
•
•
Small quantities of data
Very fast and easy to use
Safe for servers
Limitations
– CF COM Support (all versions)
– Java version incomplete (Apache POI)
September 18, 2002
Samuel R. Neff
Serving Word
HTML, XML, CSS
• Familiar
• Fast
• Flexible
September 18, 2002
Samuel R. Neff
Serving Word
Hello Word
Standard HTML document
<html>
<body>Hello! I'm a Word
document.</body>
</html>
Display in MS Word
<cfheader
name="Content-Type"
value="application/msword">
<cfheader
name="Content-Disposition"
value="attachment;
filename=HelloWord.doc">
Example: helloword.cfm
September 18, 2002
Samuel R. Neff
Serving Word
Basic Formatting
• Sections
• Pages
• Margins
@page Section1 {
size:8.5in 11.0in;
margin:1.0in 1.25in 1.0in
1.25in;
}
div.Section1 {
page:Section1;
}
Example: letter01.cfm
September 18, 2002
Samuel R. Neff
Serving Word
Paragraph Formatting
• Namespaces
<html xmlns:o="…">
•
Text wrapping
<w:WrapTextWithPunct/>
•
Margins
p { margin:0pt; }
•
Orphan control
p { mso-pagination:widoworphan; }
• White spaces
style='mso-spacerun:yes'
Example: letter02.cfm
September 18, 2002
Samuel R. Neff
Serving Word
Labels
• Tables fixed layout
mso-table-layout-alt: fixed;
•
•
Don't break rows
Specify row height
page-break-inside: avoid;
height: 1.0in;
•
Fixed width label cells
width: 189.0pt;
• Spacer cells
width: 9.0pt;
•
margin: 0in 5.3pt 0in 5.3pt;
Paragraph margins
Example: labels01.cfm
September 18, 2002
Samuel R. Neff
Serving Word
Advanced Labels
• Different sizes and layouts
–
–
–
–
–
Page Margin
Row Height
Paragraph Margins
Number of Columns
Spacers
• Reuse code
– Despite varying content
– ColdFusion Components
• Not all labels can be generated
Examples: labels02.cfm, labels03.cfm, WordLabelGenerator*.cfc
September 18, 2002
Samuel R. Neff
Serving Word
Columns
• Columns style on page
mso-columns:2 even .5in;
•
@page Section1 {}
@page Section2 {}
Sections to separate
columns and standard
layout text
• Paragraph margins for
spacing
margin-bottom:12.0pt;
•
<br clear="all" style="pagebreak-before:auto;mso-breaktype:section-break"/>
Breaks to divide document
sections
• Div tags to identify
sections
<div class="Section1">
<div class="Section2">
Example: columns01.cfm
September 18, 2002
Samuel R. Neff
Serving Word
Multi-File Documents
•
Web Archives (Multipart
MIME)
MIME-Version: 1.0
Content-Type:
•
Header part ignored
This is a Multipart MIME...
•
Boundary between parts
------=_edb95f2d9c
•
Location of each part
Content-Location:
•
Encoding type
Content-Transfer-Encoding:
•
Encoded message parts
Message parts
•
Include a list of files
filelist.xml
Examples: MultipartMIME_Example.htm, MultipartMIME.cfc
September 18, 2002
Samuel R. Neff
Serving Word
Headers & Footers
•
File links
<link rel="…" href="…">
•
Margins
mso-header-margin:.5in;
mso-footer-margin:.5in;
•
URLs
mso-header: url("…") h1;
mso-footer: url("…") f1;
•
Style attribute
mso-element: header
•
ID
id="h1"
Example: columns02.cfm
September 18, 2002
Samuel R. Neff
Serving Word
Images
• Use standard <img> tag
• Include image in the file list
• Include image in Multipart MIME message
– Component automatically encodes as Base64
Example: columns03.cfm
September 18, 2002
Samuel R. Neff
Serving Word
Resources
• Save as Web Page
• Microsoft® Office HTML and XML Reference
– http://msdn.microsoft.com/library/default.asp?url=/libra
ry/en-us/dnoffxml/html/ofxml2k.asp
• RFCs 2045 and 2046
– http://www.ietf.org/rfc/rfc2045.txt
– http://www.ietf.org/rfc/rfc2046.txt
September 18, 2002
Samuel R. Neff
Serving Word
Conclusions
• HTML/XML/CSS Faster and more stable than
COM
• Can be used for most dynamic Word applications
• Builds upon existing developers' skill set
September 18, 2002
Samuel R. Neff
Serving Word
Questions
[email protected]
September 18, 2002
Samuel R. Neff