Whatever message this page gives is out now! Go check it out!

cfdocument

Last update:
May 18, 2026
FORMAT="flashpaper" HAS BEEN DEPRECATED
For a full list of deprecated features, refer to Deprecated features.

Description

Creates PDF or FlashPaper output from a text block containing CFML and HTML.

Category

Syntax

<cfdocument 
format = "PDF|FlashPaper" 
authPassword = "authentication password" 
authUser = "authentication user name" 
backgroundVisible = "yes|no" 
bookmark = "yes|no" 
encryption = "128-bit|40-bit|none" 
filename = "filename" 
fontEmbed = "yes|no" 
formfields = "yes|no" 
formsType = "FDF|PDF|HTML|XML" 
localUrl = "yes|no" 
marginBottom = "number" 
marginLeft = "number" 
marginRight = "number" 
marginTop = "number" 
mimeType = "text/plain|application/xml|image/jpeg|image/png|image/bmp|image/gif"
name = "output variable name" 
openpassword = "password to open protected documents" 
orientation = "portrait|landscape" 
overwrite = "yes|no" 
ownerPassword = "password" 
pageHeight = "page height in inches" 
pageType = "page type" 
pageWidth = "page width in inches" 
pdfa = "yes|no" 
permissions = "permission list" 
permissionspassword = "password to access restricted permissions" 
proxyHost = "IP address or server name for proxy host" 
proxyPassword = "password for the proxy host" 
proxyPort = "port of the proxy host" 
proxyUser = "user name for the proxy host" 
saveAsName = "PDF filename" 
scale = "percentage less than 100" 
src = "URL|pathname relative to web root" 
srcfile = "absolute pathname to a file" 
tagged = "yes|no" 
unit = "in|cm" 
userAgent = "HTTP user agent identifier" 
userPassword = "password"> 
HTML and CFML code 
</cfdocument>
Note: You can specify this tag's attributes in an attributeCollection attribute whose value is a structure. Specify the structure name in the attributeCollection attribute and use the tag's attribute names as structure keys.

See also

History

ColdFusion 9: Add ppt support to the srcFile attribute. Added the following attributes to support conversion of a Word document to PDF or HTML using OpenOffice libraries:
  • formfields  attribute
  • formsType  attribute
  • openpassword  attribute
  • permissionspassword  attribute
  • pdfa  attribute
  • tagged attribute
ColdFusion 8: Added the following attributes and variables:
  • bookmark attribute
  • localUrl attribute
  • Ability to embed existing PDF forms by using the  cfpdfform  tag in the  cfdocument  tag.
  • ColdFusion determines the MIME type of a source file based on the source filename, if the mimeType attribute is not specified.
  • Ability to pass a PDF variable created with the  cfdocument  tag as the source for the  cfpdf  tag.
  • authPassword, authUser, proxyHost, proxyPassword, proxyPort, proxyUser, and userAgent attributes
  • saveAsName  attribute
  • totalsectionpagecount  and  currentsectionpagenumber  scope variables.
ColdFusion MX 7.01: Added the src, srcfile, and mimetype attributes.ColdFusion MX 7: Added this tag.

Attributes

Attribute
Req/Opt
Default
Description
authPassword
Optional
Password sent to the target URL for Basic Authentication. Combined with username to form a base64 encoded string that is passed in the Authenticate header. Does not provide support for Integrated Windows, NTLM, or Kerebos authentication.
authUser
Optional
User name sent to the target URL for Basic Authentication. Combined with password to form a base64 encoded string that is passed in the Authenticate header. Does not provide support for Integrated Windows, NTLM, or Kerebos authentication.
backgroundVisible
Optional
no
Specifies whether the background prints when the user prints the document:
  • yes: includes the background when printing.
  • no: does not includes the background when printing.
bookmark
Optional
no
Specifies whether bookmarks are created in the document:
  • yes: creates bookmarks.
  • no: does not create bookmarks.
encryption
Optional
none
(format="PDF" only) Specifies whether the output is encrypted:
  • 128-bit
  • 40-bit
  • none
filename
Optional
Pathname of a file to contain the PDF or FlashPaper output.

If you omit the filename attribute, ColdFusion displays the output in the browser.
fontEmbed
Optional
yes
Specifies whether ColdFusion embeds fonts in the output:
  • yes: embeds fonts.
  • no: does not embed fonts.
  • selective: embed sall fonts except Java fonts and core fonts.
format
Required
Report format:
  • PDF
  • FlashPaper
formfields
Optional
yes
This attribute is available only if you have integrated OpenOffice with ColdFusion.A Boolean value that specifies if form fields are exported as widgets or only their fixed print representation is exported.
formstype
Optional
FDF
This attribute is available only if you have integrated OpenOffice with ColdFusion.Specifies the submitted format of a PDF form. It can be one of the following values:
  • FDF
  • PDF
  • HTML
  • XML
localUrl
Optional
no
Specifies whether to retrieve image files directly from the local drive:
  • yes: ColdFusion retrieves image files directly from the local drive rather than by using HTTP, HTTPS, or proxy.
  • no: ColdFusion uses HTTP, HTTPS, or proxy to retrieve image files even if the files are stored locally. For more information, see the "Using an image file URL" section.
marginBottom
Optional
Bottom margin in inches (default) or centimeters. To specify the bottom margin in centimeters, include the unit=cm attribute.
marginLeft
Optional
Left margin in inches (default) or centimeters. To specify the left margin in centimeters, include the unit=cm attribute.
marginRight
Optional
Right margin in inches (default) or centimeters. To specify the right margin in centimeters, include the unit=cm attribute.
marginTop
Optional
Top margin in inches (default) or centimeters. To specify the top margin in centimeters, include the unit=cm attribute.
mimeType
Optional
text/ html
MIME type of the source document. Supported MIME types are:
  • text/ html
  • text/plain
  • application/ xml
  • image/ bmp
  • image/jpeg
  • image/png
  • image/gif If you do not specify this attribute explicitly, ColdFusion uses the filename to determine the MIME type.
name
Optional
Name of an existing variable into which the tag stores the PDF or FlashPaper output.
openpassword
Optional
This attribute is available only if you have integrated OpenOffice with ColdFusion.Password required to open a password-protected document.
orientation
Optional
portrait
Page orientation:
  • portrait
  • landscape
overwrite
Optional
no
Specifies whether ColdFusion overwrites an existing file. Used in conjunction with the filename attribute.
ownerPassword
Optional
(format="PDF" only) Specifies the owner password.Cannot be same as userPassword.
pageHeight
Optional
Page height in inches (default) or centimeters. This attribute is only valid if pagetype=custom. To specify page height in centimeters, include the unit=cm attribute.
pageType
Optional
letter
Page type into which ColdFusion generates the report:
  • legal: 8.5 inches x 14 inches.
  • letter: 8.5 inches x 11 inches.
  • A4: 8.27 inches x 11.69 inches.
  • A5: 5.81 inches x 8.25 inches.
  • B4: 9.88 inches x 13.88 inches.
  • B5: 7 inches x 9.88 inches.
  • B4-JIS: 10.13 inches x 14.31 inches.
  • B5-JIS: 7.19 inches x 10.13 inches.
  • custom: custom height and width. If you specify custom , also specify the pageHeight and pageWidth attributes, can optionally specify margin attributes and whether the units are inches or centimeters.
pageWidth
Optional
Page width in inches (default) or centimeters. This attribute is only valid if pageType=custom. To specify page width in centimeters, include the unit=cm attribute.
pdfa
Optional
no
This attribute is available only if you have integrated OpenOffice with ColdFusion.A Boolean value that specifies if you need to create a PDF of type PDF/A-1 (ISO 19005-1:2005 ) .
permissionpasswrd
Optional
This attribute is available only if you have integrated OpenOffice with ColdFusion.Password required to access restricted permissions. The restricted permissions are specified using the permissions attribute.
permissions
Optional
(format="PDF" only) Sets one or more of the following permissions:
  • AllowPrinting
  • AllowModifyContents
  • AllowCopy
  • AllowModifyAnnotations
  • AllowFillIn
  • AllowScreenReaders
  • AllowAssembly
  • AllowDegradedPrinting Separate multiple permissions with commas.
proxyHost
Optional
Host name or IP address of a proxy server to which to send the request.
proxyPassword
Optional
Password required by the proxy server.
proxyPort
Optional
80
The port to connect to on the proxy server.
proxyUser
Optional
User name to provide to the proxy server.
scale
Optional
Calculated by ColdFusion
Scale factor as a percentage. Use this option to reduce the size of the HTML output so that it fits on that paper. Specify a number less than 100.
saveAsName
Optional
(format="PDF" only) The filename that appears in the SaveAs dialog when a user saves a PDF file written to the browser.
src
Optional
URL or the relative path to the web root. You cannot specify both the src and srcfile attributes. The file must be in a browser-writable format such as, HTML, HTM, BMP, PNG, and so on.
srcfile
Optional
Absolute path of a file that is on the server. You cannot specify both the src and srcfile attributes. The file must be a PPT file, a Word file, or be in a browser-writable format such as, HTML, HTM, BMP, PNG, and so on.
tagged
Optional
no
This attribute is available only if you have integrated OpenOffice with ColdFusion.A Boolean value that determines if the PDF is created using the Tagged PDF tag.
unit
Optional
in
Default unit for the pageHeight, pageWidth , and margin attributes:
  • in: inches.
  • cm: centimeters.
userAgent
Optional
ColdFusion
Text to put in the HTTP User-Agent request header field. Used to identify the request client software.
userPassword
Optional
(format="PDF" only) Specifies a user password.Cannot be same as ownerPassword .
Usage
Use the cfdocument tag to render HTML and CFML output into PDF or FlashPaper format. ColdFusion does not return HTML and CFML outside of the <cfdocument> </cfdocument> pair.

The cfdocument tag can render HTML that supports the following standards:
  • HTML 4.01
  • XML 1.0
  • DOM Level 1 and 2
  • CSS1 and CSS2 (For more information, see the "Supported CSS styles" section).

    The cfdocument tag does not support the Internet Explorer-specific HTML generated by Microsoft Word.Use the following syntax in the filenameattribute to specify an in-memory file, which is not written to disk. In-memory files speed processing of transient data.
    ram:///filepath
    The filepath can include directories, for example ram:///petStore/tracking/ordersummary.pdf. Create the directories in the path before you specify the file. For more information on using in-memory files, see Working with in-memory files in the Developing ColdFusion Applications.
    You can use the src, srcfile , and mimeType attributes to create PDF or FlashPaper output from a specified file or URL. Use the src and srcfile attributes instead of using the cfhttp tag to display the result in the cfdocument tag. When you specify the src or srcfile attributes, do not include any other content inside the cfdocument tag: ColdFusion ignores the additional content. The PDF or FlashPaper document returned by the cfdocument tag overwrites any previous HTML in the input stream and ignores any HTML after the </cfdocument> tag.
    You cannot embed a cfreport tag in a cfdocumenttag .
    Note: If you notice that the header text is cropped in the cfdocument tag output, increase the value of the marginTop attribute.
Note: The cfdocument will not work as expected if the input statement is type="file". For example,
<input class="entryx" id="Photo" name="Photo" onkeypress="return noEnter(event)" size="40" type="file" value="" />
As a work-around, run the PDFg service from the command line.

Supported CSS styles

The cfdocument tag supports the following CSS styles:
background
background-attachment
background-color
background-image
background-position
background-repeat
border
border-bottom
border-bottom-color
border-bottom-style (solid border only)
border-bottom-width
border-color
border-left
border-left-color
border-left-style (solid border only)
border-left-width
border-right
border-right-color
border-right-style (solid border only)
border-right-width
border-spacing
border-style (solid border only)
border-top
border-top-color
border-top-style (solid border only)
border-top-width
border-width
bottom
clear
clip
color
content (strings, counters only)
counter-increment
counter-reset
cursor
display
float
font
font-family
font-size
font-style
font-weight
height
left
line-height
line-style-type
margin
margin-bottom
margin-left
margin-right
margin-top
outline
outline-color
outline-style (solid, dotted, dashed only)
outline-width
padding
padding-bottom
padding-left
padding-right
padding-top
page-break-after
page-break-before
page-break-inside
position
right
text-align (left, right, and center)
text-decoration
text-indent
top
unicode-bidi
vertical-align
visibility
white space (normal, nowrap only)
width
z-index

Using an image file URL

For optimal performance and reliability, Adobe recommends that you specify a local file URL for images stored on the server. In the following example, the cfdocument tag requests the server for images over HTTP even though the image files are stored locally:
<cfdocument format="PDF"> 
<table> 
<tr> 
<td>bird</td> 
<td><img src="images/bird.jpg"></td> 
</tr> 
<tr> 
<td>fruit</td> 
<td><img src="images/fruit.jpg"></td> 
</tr> 
<tr> 
<td>rose</td> 
<td><img src="images/rose.jpg"></td> 
</tr> 
</table> 
</cfdocument>
Also, in some applications, the browser displays a Red X image error instead of the image in the browser. For better performance, and to avoid Red X image errors, set the localUrl attribute to yes:
<cfdocument localUrl="yes" format="PDF"> 
<table> 
<tr> 
<td>bird</td> 
<td><img src="images/bird.jpg"></td> 
</tr> 
<tr> 
<td>fruit</td> 
<td><img src="images/fruit.jpg"></td> 
</tr> 
<tr> 
<td>rose</td> 
<td><img src="images/rose.jpg"></td> 
</tr> 
</table> 
</cfdocument>

Scope variables

When you use the cfdocument tag, ColdFusion creates a scope named cfdocument. This scope contains the following variables:
  • currentpagenumber
  • totalpagecount
  • totalsectionpagecount
  • currentsectionpagenumber
    ColdFusion lets you use the scope variables inside any expression within a cfdocumentitem tag. For example, you can use the currentpagenumbervariable to place the section name on even pages and the chapter name on odd pages in the header, as follows:
<cfdocument format="flashpaper"> 
<cfdocumentitem type="header" evalAtPrint="true"> 
<cfif (cfdocument.currentpagenumber mod 2) is 0> 
<cfoutput>#cfdocument.totalpagecount#</cfoutput> 
<cfelse> 
<cfoutput>#cfdocument.currentpagenumber#</cfoutput> 
</cfif> 
</cfdocumentitem> 
... 
</cfdocument>
If you define the cfdocumentsection tag within the cfdocument tag, then specify the totalsectionpagecountvariable as follows:
<cfdocument format="pdf"> 
<cfdocumentitem type="header" evalatprint="true" > 
<cfif (cfdocument.currentpagenumber mod 2) is 0> 
<cfoutput>#cfdocument.totalpagecount#</cfoutput> 
<cfelse> 
<cfoutput>#cfdocument.currentpagenumber#</cfoutput> 
</cfif> 
<cfoutput>cfdocument.currentpagenumber :#cfdocument.currentpagenumber#</cfoutput> 
<cfoutput>cfdocument.totalpagecount :#cfdocument.totalpagecount#</cfoutput> 
<cfoutput>cfdocument.totalsectionpagecount :#cfdocument.totalsectionpagecount#</cfoutput> 
<cfoutput>cfdocument.currentsectionpagenumber :#cfdocument.currentsectionpagenumber#</cfoutput> 
</cfdocumentitem> 

<cfdocumentitem type="footer" evalatprint="true" > 
<cfif ! (cfdocument.currentpagenumber mod 2) is 0> 
<cfoutput>if#cfdocument.totalpagecount#</cfoutput> 
<cfelse> 
<cfoutput>else#cfdocument.currentpagenumber#</cfoutput>
</cfif> 
</cfdocumentitem> 
<cfdocumentsection >Example Text 
</cfdocumentsection> 
</cfdocument>

Bookmarks

ColdFusion 9 supports bookmarks. In the cfdocument tag, set the bookmark attribute to yes. Then specify the bookmark name for each cfdocumentsection tag.

The following example shows how to specify bookmarks for document sections:
<!--- This example creates two bookmarks named "Section 1" and "Section 2" in a PDF file. ---> 
<cfdocument format="pdf" bookmark="yes"> 
<cfdocumentsection name="Section 1"> 
<!--- Insert HTML content here.---> 
</cfdocumentsection> 
<cfdocumentsection name="Section 2"> 
<!--- Insert HTML content here. ---> 
</cfdocumentsection> 
</cfdocument>

Handling expressions

If you use characters, < or >, in the cfdocument tag, the output document will not display these characters. This is expected because the characters < and > are delimiters used by a nHTML or an XML tag. The following code will not display < or > in the document.
<cfdocument format="PDF">
<cfoutput>This is a test content whose value is <= 0.89%</cfoutput>
</cfdocument>
Alternatively, you can use &lt; and &gt; to represent the characters.
However, you can use the xmlFormat function to display similar characters. The following snippet will display the characters:
<cfdocument format="PDF">
     <cfoutput>#xmlFormat("This is a test content whose value is <= 0.89")#</cfoutput>
 </cfdocument>

Example

<!--- The following example shows how to use the cfdocument scope variables to generate section numbers and page numbers. ---> 

<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> 

<cfdocumentsection> 
<h1>Section 1</h1> 
<cfloop from=1 to=50 index="i"> 
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.<p> 
</cfloop> 
</cfdocumentsection> 

<cfdocumentsection> 
<h1>Section 2</h1> 
<cfloop from=1 to=50 index="i"> 
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.<p> 
</cfloop> 
</cfdocumentsection> 

<cfdocumentsection> 
<h1>Section 3</h1> 
<cfloop from=1 to=50 index="i"> 
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.<p> 
</cfloop> 
</cfdocumentsection> 
</cfdocument>

Real-world uses of the cfdocument tag

E-commerce order fulfillment system

Your online store needs to automatically generate professional PDF invoices for customer orders. These invoices must include company branding, itemized order details, tax calculations, shipping information, and payment terms. Customers receive these PDFs via email, and accounting keeps copies for records.
Problem statement
  • Need professional-looking invoices in PDF format
  • Must include company logo, branding, and contact information
  • Itemized list of products with prices, quantities, and totals
  • Tax calculations and shipping costs clearly displayed
  • Page headers and footers with invoice number and page numbers
Solution
The cdocument tag converts HTML to professional PDF documents, adds consistent branding and page numbers, uses CSS for professional layout and design, and sets margins, orientation, or page size.
<h1>Invoice PDF Generator Demo</h1>

<p><strong>What This Demo Shows:</strong> How to use cfdocument to generate professional PDF invoices.</p>
<hr>

<cfscript>
    // Sample invoice data
    invoice = {
        invoiceNumber: "INV-2024-001234",
        invoiceDate: now(),
        dueDate: dateAdd("d", 30, now()),
        
        // Company information
        company: {
            name: "TechStore Inc.",
            address: "123 Commerce Street",
            city: "San Francisco, CA 94102",
            phone: "(555) 123-4567",
            email: "billing@techstore.com"
        },
        
        // Customer information
        customer: {
            name: "John Smith",
            company: "Acme Corporation",
            address: "456 Business Ave",
            city: "New York, NY 10001",
            email: "john.smith@acme.com"
        },
        
        // Line items (pre-sorted)
        items: [
            {id: 1, description: "Wireless Mouse", quantity: 2, unitPrice: 29.99},
            {id: 2, description: "USB-C Cable (6ft)", quantity: 3, unitPrice: 12.99},
            {id: 3, description: "Laptop Stand", quantity: 1, unitPrice: 45.50},
            {id: 4, description: "Keyboard - Mechanical", quantity: 1, unitPrice: 89.99}
        ],
        
        // Totals
        subtotal: 0,
        taxRate: 0.085,
        taxAmount: 0,
        shippingCost: 15.00,
        total: 0
    };
    
    // Calculate totals
    for (item in invoice.items) {
        invoice.subtotal += item.quantity * item.unitPrice;
    }
    invoice.taxAmount = invoice.subtotal * invoice.taxRate;
    invoice.total = invoice.subtotal + invoice.taxAmount + invoice.shippingCost;
</cfscript>

<h2>Example 1: Generate Invoice PDF (Display in Browser)</h2>

<cfdocument format="pdf" pageType="letter" orientation="portrait" 
    margintop="0.5" marginbottom="0.5" marginleft="0.75" marginright="0.75">
    
    <!--- Header --->
    <cfdocumentitem type="header">
        <table width="100%" style="border-bottom: 2px solid ##333; padding-bottom: 10px;">
            <tr>
                <td style="width: 70%; font-size: 18px; font-weight: bold; color: ##0066cc;">
                    <cfoutput>#invoice.company.name#</cfoutput>
                </td>
                <td style="width: 30%; text-align: right; font-size: 12px;">
                    <cfoutput>Invoice ##: #invoice.invoiceNumber#</cfoutput>
                </td>
            </tr>
        </table>
    </cfdocumentitem>
    
    <!--- Footer --->
    <cfdocumentitem type="footer">
        <table width="100%" style="border-top: 1px solid ##ccc; padding-top: 10px; font-size: 10px; color: ##666;">
            <tr>
                <td style="width: 50%;">
                    <cfoutput>#invoice.company.name# | #invoice.company.phone# | #invoice.company.email#</cfoutput>
                </td>
                <td style="width: 50%; text-align: right;">
                    <cfoutput>Page #cfdocument.currentpagenumber# of #cfdocument.totalpagecount#</cfoutput>
                </td>
            </tr>
        </table>
    </cfdocumentitem>
    
    <!--- Document body --->
    <div style="font-family: Arial, sans-serif; font-size: 12px;">
        
        <h1 style="color: ##0066cc; margin-top: 20px;">INVOICE</h1>
        
        <!--- Company and Customer Info --->
        <table width="100%" style="margin-top: 20px;">
            <tr>
                <td style="width: 50%; vertical-align: top;">
                    <p style="font-weight: bold;">From:</p>
                    <cfoutput>
                        <p>#invoice.company.name#<br>
                        #invoice.company.address#<br>
                        #invoice.company.city#<br>
                        Phone: #invoice.company.phone#<br>
                        Email: #invoice.company.email#</p>
                    </cfoutput>
                </td>
                <td style="width: 50%; vertical-align: top;">
                    <p style="font-weight: bold;">Bill To:</p>
                    <cfoutput>
                        <p>#invoice.customer.name#<br>
                        #invoice.customer.company#<br>
                        #invoice.customer.address#<br>
                        #invoice.customer.city#<br>
                        Email: #invoice.customer.email#</p>
                    </cfoutput>
                </td>
            </tr>
        </table>
        
        <!--- Invoice Details --->
        <table width="100%" style="margin-top: 20px; background-color: ##f0f0f0; padding: 10px;">
            <tr>
                <td style="width: 50%;">
                    <cfoutput>
                        <p><strong>Invoice Date:</strong> #dateFormat(invoice.invoiceDate, "mmmm d, yyyy")#</p>
                    </cfoutput>
                </td>
                <td style="width: 50%;">
                    <cfoutput>
                        <p><strong>Due Date:</strong> #dateFormat(invoice.dueDate, "mmmm d, yyyy")#</p>
                    </cfoutput>
                </td>
            </tr>
        </table>
        
        <!--- Line Items --->
        <table width="100%" style="margin-top: 30px; border-collapse: collapse;" border="1" cellpadding="8">
            <tr style="background-color: ##0066cc; color: white;">
                <th style="text-align: left;">Item</th>
                <th style="text-align: center;">Quantity</th>
                <th style="text-align: right;">Unit Price</th>
                <th style="text-align: right;">Total</th>
            </tr>
            <cfloop array="#invoice.items#" index="item">
                <cfset itemTotal = item.quantity * item.unitPrice>
                <cfoutput>
                    <tr>
                        <td>#item.description#</td>
                        <td style="text-align: center;">#item.quantity#</td>
                        <td style="text-align: right;">$#numberFormat(item.unitPrice, "0.00")#</td>
                        <td style="text-align: right;">$#numberFormat(itemTotal, "0.00")#</td>
                    </tr>
                </cfoutput>
            </cfloop>
        </table>
        
        <!--- Totals --->
        <table width="100%" style="margin-top: 20px;">
            <tr>
                <td style="width: 70%;"></td>
                <td style="width: 30%;">
                    <table width="100%" border="1" cellpadding="8" style="border-collapse: collapse;">
                        <cfoutput>
                            <tr>
                                <td><strong>Subtotal:</strong></td>
                                <td style="text-align: right;">$#numberFormat(invoice.subtotal, "0.00")#</td>
                            </tr>
                            <tr>
                                <td><strong>Tax (#numberFormat(invoice.taxRate * 100, "0.0")#%):</strong></td>
                                <td style="text-align: right;">$#numberFormat(invoice.taxAmount, "0.00")#</td>
                            </tr>
                            <tr>
                                <td><strong>Shipping:</strong></td>
                                <td style="text-align: right;">$#numberFormat(invoice.shippingCost, "0.00")#</td>
                            </tr>
                            <tr style="background-color: ##0066cc; color: white; font-size: 14px;">
                                <td><strong>TOTAL:</strong></td>
                                <td style="text-align: right;"><strong>$#numberFormat(invoice.total, "0.00")#</strong></td>
                            </tr>
                        </cfoutput>
                    </table>
                </td>
            </tr>
        </table>
        
        <!--- Payment Terms --->
        <div style="margin-top: 40px; padding: 15px; background-color: ##f9f9f9; border-left: 4px solid ##0066cc;">
            <p style="font-weight: bold;">Payment Terms:</p>
            <p>Payment is due within 30 days of invoice date. Please include invoice number with payment.</p>
            <p><strong>Make checks payable to:</strong> <cfoutput>#invoice.company.name#</cfoutput></p>
            <p style="margin-top: 20px;"><strong>Thank you for your business!</strong></p>
        </div>
        
    </div>
</cfdocument>

<hr>

<p><strong>PDF generated successfully!</strong> The invoice was displayed inline in your browser.</p>

<h2>Example 2: Save Invoice PDF to File</h2>

<cfscript>
    // Create a simple invoice for file save demo
    simpleInvoice = {
        number: "INV-2024-" & randRange(1000, 9999),
        date: now(),
        customerName: "Jane Doe",
        amount: 299.99
    };
</cfscript>

<cfset pdfFilename = "invoice_" & dateFormat(now(), "yyyymmdd") & "_" & timeFormat(now(), "HHmmss") & ".pdf">
<cfset pdfPath = expandPath("./") & pdfFilename>

<cftry>
    <cfdocument format="pdf" filename="#pdfPath#" overwrite="true">
        <div style="font-family: Arial; padding: 40px;">
            <h1>Invoice</h1>
            <cfoutput>
                <p><strong>Invoice Number:</strong> #simpleInvoice.number#</p>
                <p><strong>Date:</strong> #dateFormat(simpleInvoice.date, "mmmm d, yyyy")#</p>
                <p><strong>Customer:</strong> #simpleInvoice.customerName#</p>
                <p><strong>Amount Due:</strong> $#numberFormat(simpleInvoice.amount, "0.00")#</p>
            </cfoutput>
        </div>
    </cfdocument>
    
    <cfoutput>
        <p><strong>✓ PDF saved successfully!</strong></p>
        <p>Filename: #pdfFilename#</p>
        <p>Location: #pdfPath#</p>
        <p><a href="#pdfFilename#" target="_blank">Download Invoice PDF</a></p>
    </cfoutput>
    
    <cfcatch type="any">
        <cfoutput>
            <p><strong>✗ Error saving PDF:</strong> #cfcatch.message#</p>
        </cfoutput>
    </cfcatch>
</cftry>

<hr>

Business Intelligence reporting system

Your sales management team needs monthly performance reports in PDF format for distribution to executives, stakeholders, and regional managers. These reports include sales data, charts, performance metrics, and comparative analysis. PDFs are preferred for offline review, printing, and archival.
Problem statement
  • Need professional monthly sales reports in PDF format
  • Must include multiple pages with different sections
  • Require page breaks, headers, and footers
  • Need to display tables, charts, and formatted data
  • Reports must be consistent across viewing platforms
Solution
The cfdocument tag provides automatic pagination for long reports, organizes reports into logical sections, controls where pages are split, or adds branding and navigation.
<h1>Monthly Sales Report PDF Demo</h1>

<p><strong>What This Demo Shows:</strong> How to use cfdocument to generate multi-page business reports with sections and page breaks.</p>
<hr>

<cfscript>
    // Report data
    reportData = {
        month: "November",
        year: 2024,
        generatedDate: now(),
        
        // Summary metrics
        summary: {
            totalSales: 487500.00,
            totalOrders: 342,
            averageOrderValue: 1425.73,
            newCustomers: 45,
            returningCustomers: 89
        },
        
        // Regional sales (pre-sorted)
        regionalSales: [
            {region: "East", sales: 145000.00, orders: 98, growth: 12.5},
            {region: "West", sales: 198000.00, orders: 134, growth: 18.3},
            {region: "North", sales: 87500.00, orders: 67, growth: -3.2},
            {region: "South", sales: 57000.00, orders: 43, growth: 5.8}
        ],
        
        // Top products
        topProducts: [
            {name: "Laptop Pro 15", units: 145, revenue: 217500.00},
            {name: "Wireless Mouse", units: 342, revenue: 10260.00},
            {name: "Monitor 27 inch", units: 89, revenue: 35600.00},
            {name: "Keyboard Mechanical", units: 156, revenue: 14040.00}
        ]
    };
</cfscript>

<h2>Generate Monthly Sales Report PDF</h2>

<cfdocument format="pdf" pageType="letter" orientation="portrait" bookmark="yes"
    margintop="0.75" marginbottom="0.75" marginleft="0.75" marginright="0.75">
    
    <!--- Header --->
    <cfdocumentitem type="header" evalatprint="true">
        <table width="100%" style="border-bottom: 2px solid ##0066cc;">
            <tr>
                <td style="width: 60%; font-size: 14px; font-weight: bold; color: ##0066cc;">
                    <cfoutput>Monthly Sales Report - #reportData.month# #reportData.year#</cfoutput>
                </td>
                <td style="width: 40%; text-align: right; font-size: 10px; color: ##666;">
                    <cfoutput>Page #cfdocument.currentpagenumber# of #cfdocument.totalpagecount#</cfoutput>
                </td>
            </tr>
        </table>
    </cfdocumentitem>
    
    <!--- Footer --->
    <cfdocumentitem type="footer" evalatprint="true">
        <table width="100%" style="border-top: 1px solid ##ccc; padding-top: 5px;">
            <tr>
                <td style="width: 50%; font-size: 9px; color: ##666;">
                    <cfoutput>Generated: #dateFormat(reportData.generatedDate, "mm/dd/yyyy")# at #timeFormat(reportData.generatedDate, "h:mm tt")#</cfoutput>
                </td>
                <td style="width: 50%; text-align: right; font-size: 9px; color: ##666;">
                    Confidential - For Internal Use Only
                </td>
            </tr>
        </table>
    </cfdocumentitem>
    
    <!--- Section 1: Executive Summary --->
    <cfdocumentsection name="Executive Summary">
        <div style="font-family: Arial, sans-serif; font-size: 12px;">
            
            <h1 style="color: ##0066cc; margin-top: 20px;">
                <cfoutput>#reportData.month# #reportData.year# Sales Report</cfoutput>
            </h1>
            
            <h2 style="color: ##333; border-bottom: 2px solid ##0066cc; padding-bottom: 5px;">Executive Summary</h2>
            
            <!--- Key Metrics Grid --->
            <table width="100%" style="margin-top: 20px;" cellpadding="15">
                <tr>
                    <td style="width: 33%; background-color: ##e3f2fd; text-align: center; border: 1px solid ##90caf9;">
                        <p style="font-size: 10px; color: ##666; margin: 0;">Total Sales</p>
                        <cfoutput>
                            <p style="font-size: 24px; font-weight: bold; color: ##0066cc; margin: 5px 0;">$#numberFormat(reportData.summary.totalSales, "0,000")#</p>
                        </cfoutput>
                    </td>
                    <td style="width: 33%; background-color: ##e8f5e9; text-align: center; border: 1px solid ##a5d6a7;">
                        <p style="font-size: 10px; color: ##666; margin: 0;">Total Orders</p>
                        <cfoutput>
                            <p style="font-size: 24px; font-weight: bold; color: ##2e7d32; margin: 5px 0;">#reportData.summary.totalOrders#</p>
                        </cfoutput>
                    </td>
                    <td style="width: 33%; background-color: ##fff3e0; text-align: center; border: 1px solid ##ffb74d;">
                        <p style="font-size: 10px; color: ##666; margin: 0;">Avg Order Value</p>
                        <cfoutput>
                            <p style="font-size: 24px; font-weight: bold; color: ##e65100; margin: 5px 0;">$#numberFormat(reportData.summary.averageOrderValue, "0,000")#</p>
                        </cfoutput>
                    </td>
                </tr>
            </table>
            
            <!--- Customer Metrics --->
            <div style="margin-top: 30px; padding: 15px; background-color: ##f5f5f5;">
                <h3 style="color: ##333; margin-top: 0;">Customer Metrics</h3>
                <cfoutput>
                    <p>New Customers: <strong>#reportData.summary.newCustomers#</strong></p>
                    <p>Returning Customers: <strong>#reportData.summary.returningCustomers#</strong></p>
                    <p>Customer Retention Rate: <strong>#numberFormat((reportData.summary.returningCustomers / (reportData.summary.newCustomers + reportData.summary.returningCustomers)) * 100, "0.0")#%</strong></p>
                </cfoutput>
            </div>
            
        </div>
    </cfdocumentsection>
    
    <!--- Page Break --->
    <cfdocumentitem type="pagebreak" />
    
    <!--- Section 2: Regional Performance --->
    <cfdocumentsection name="Regional Performance">
        <div style="font-family: Arial, sans-serif; font-size: 12px;">
            
            <h2 style="color: ##333; border-bottom: 2px solid ##0066cc; padding-bottom: 5px;">Regional Performance</h2>
            
            <table width="100%" style="margin-top: 20px; border-collapse: collapse;" border="1" cellpadding="10">
                <tr style="background-color: ##0066cc; color: white;">
                    <th style="text-align: left;">Region</th>
                    <th style="text-align: right;">Sales</th>
                    <th style="text-align: right;">Orders</th>
                    <th style="text-align: right;">Growth</th>
                </tr>
                <cfloop array="#reportData.regionalSales#" index="region">
                    <cfset growthColor = region.growth GTE 0 ? "##2e7d32" : "##c62828">
                    <cfset growthIcon = region.growth GTE 0 ? "▲" : "▼">
                    <cfoutput>
                        <tr>
                            <td><strong>#region.region#</strong></td>
                            <td style="text-align: right;">$#numberFormat(region.sales, "0,000")#</td>
                            <td style="text-align: right;">#region.orders#</td>
                            <td style="text-align: right; color: #growthColor#;">
                                #growthIcon# #numberFormat(abs(region.growth), "0.0")#%
                            </td>
                        </tr>
                    </cfoutput>
                </cfloop>
                <cfoutput>
                    <tr style="background-color: ##f5f5f5; font-weight: bold;">
                        <td>TOTAL</td>
                        <td style="text-align: right;">$#numberFormat(reportData.summary.totalSales, "0,000")#</td>
                        <td style="text-align: right;">#reportData.summary.totalOrders#</td>
                        <td></td>
                    </tr>
                </cfoutput>
            </table>
            
            <!--- Regional Insights --->
            <div style="margin-top: 30px; padding: 15px; background-color: ##e3f2fd; border-left: 4px solid ##0066cc;">
                <h3 style="margin-top: 0;">Key Insights:</h3>
                <ul>
                    <li><strong>West Region</strong> continues to lead with 18.3% growth</li>
                    <li><strong>East Region</strong> shows steady 12.5% growth</li>
                    <li><strong>North Region</strong> requires attention (-3.2% decline)</li>
                    <li><strong>South Region</strong> demonstrates stable 5.8% growth</li>
                </ul>
            </div>
            
        </div>
    </cfdocumentsection>
    
    <!--- Page Break --->
    <cfdocumentitem type="pagebreak" />
    
    <!--- Section 3: Top Products --->
    <cfdocumentsection name="Top Products">
        <div style="font-family: Arial, sans-serif; font-size: 12px;">
            
            <h2 style="color: ##333; border-bottom: 2px solid ##0066cc; padding-bottom: 5px;">Top Performing Products</h2>
            
            <table width="100%" style="margin-top: 20px; border-collapse: collapse;" border="1" cellpadding="10">
                <tr style="background-color: ##2e7d32; color: white;">
                    <th style="text-align: left;">Product Name</th>
                    <th style="text-align: right;">Units Sold</th>
                    <th style="text-align: right;">Revenue</th>
                </tr>
                <cfloop array="#reportData.topProducts#" index="product">
                    <cfoutput>
                        <tr>
                            <td><strong>#product.name#</strong></td>
                            <td style="text-align: right;">#product.units#</td>
                            <td style="text-align: right;">$#numberFormat(product.revenue, "0,000")#</td>
                        </tr>
                    </cfoutput>
                </cfloop>
            </table>
            
            <!--- Recommendations --->
            <div style="margin-top: 30px; padding: 15px; background-color: ##fff3e0; border-left: 4px solid ##ff9800;">
                <h3 style="margin-top: 0;">Recommendations:</h3>
                <ol>
                    <li>Increase inventory for Laptop Pro 15 based on strong demand</li>
                    <li>Bundle Wireless Mouse with laptop purchases for higher margins</li>
                    <li>Promote Monitor 27" to existing laptop customers</li>
                    <li>Develop marketing campaign for mechanical keyboards</li>
                </ol>
            </div>
            
            <!--- Report Summary --->
            <div style="margin-top: 40px; padding: 20px; background-color: ##f5f5f5; border: 2px solid ##0066cc;">
                <h3 style="color: ##0066cc; margin-top: 0;">Report Summary</h3>
                <cfoutput>
                    <p><strong>#reportData.month# #reportData.year#</strong> shows strong overall performance with total sales of <strong>$#numberFormat(reportData.summary.totalSales, "0,000")#</strong> across <strong>#reportData.summary.totalOrders#</strong> orders.</p>
                    <p>West and East regions drive growth, while North region requires strategic attention. Product portfolio demonstrates healthy diversification with strong performance in high-value items.</p>
                </cfoutput>
            </div>
            
        </div>
    </cfdocumentsection>
    
</cfdocument>

<p><strong>✓ Multi-page sales report PDF generated successfully!</strong></p>
<p>The report includes 3 sections with bookmarks, headers, footers, and automatic pagination.</p>

<hr>

Online training platform- Certificate of completion

Your e-learning platform offers courses and needs to automatically generate professional certificates of completion for students. These certificates must include the student's name, course details, completion date, and an official-looking design. Certificates are emailed to students and archived for verification purposes.
Problem statement
  • Need professional-looking completion certificates
  • Must include student and course information
  • Require consistent branding and design
  • Should look official for resume/LinkedIn purposes
  • Need to generate hundreds of certificates automatically
Solution
The cfdocument tag generates certificate-quality documents, creates elegant, branded designs with CSS, or personalizes each certificate with student data.
<cfscript>
    // Certificate data
    certificate = {
        certificateNumber: "CERT-" & year(now()) & "-" & randRange(10000, 99999),
        studentName: "Jennifer Martinez",
        courseName: "Advanced ColdFusion Development",
        courseHours: 40,
        completionDate: dateAdd("d", -5, now()),
        instructorName: "Dr. Michael Chen",
        issueDate: now(),
        institution: "TechLearning Academy"
    };
</cfscript>

<h2>Generate Certificate of Completion PDF</h2>

<cfdocument format="pdf" pageType="letter" orientation="landscape" 
    margintop="0" marginbottom="0" marginleft="0" marginright="0">
    
    <div style="
        width: 100%; 
        height: 100vh; 
        background: linear-gradient(135deg, ##667eea 0%, ##764ba2 100%);
        font-family: Georgia, serif;
        position: relative;
        padding: 40px;
        box-sizing: border-box;
    ">
        
        <!--- Decorative border --->
        <div style="
            border: 8px solid gold;
            border-radius: 10px;
            background-color: white;
            padding: 50px;
            height: calc(100% - 80px);
            position: relative;
        ">
            
            <!--- Inner decorative border --->
            <div style="
                border: 2px solid ##333;
                padding: 40px;
                height: 100%;
                text-align: center;
            ">
                
                <!--- Certificate Header --->
                <div style="margin-bottom: 30px;">
                    <cfoutput>
                        <p style="font-size: 16px; color: ##666; letter-spacing: 3px; margin: 0;">
                            #uCase(certificate.institution)#
                        </p>
                    </cfoutput>
                </div>
                
                <!--- Certificate Title --->
                <h1 style="
                    font-size: 48px;
                    color: ##1a1a1a;
                    margin: 20px 0;
                    font-weight: normal;
                    letter-spacing: 2px;
                ">
                    Certificate of Completion
                </h1>
                
                <!--- Divider --->
                <div style="
                    width: 200px;
                    height: 3px;
                    background-color: gold;
                    margin: 20px auto;
                "></div>
                
                <!--- This is to certify text --->
                <p style="font-size: 16px; color: ##666; margin: 30px 0 10px 0;">
                    This is to certify that
                </p>
                
                <!--- Student Name --->
                <cfoutput>
                    <h2 style="
                        font-size: 42px;
                        color: ##1a1a1a;
                        margin: 10px 0 30px 0;
                        font-style: italic;
                        text-decoration: underline;
                    ">
                        #certificate.studentName#
                    </h2>
                </cfoutput>
                
                <!--- Has successfully completed text --->
                <p style="font-size: 16px; color: ##666; margin: 10px 0;">
                    has successfully completed the course
                </p>
                
                <!--- Course Name --->
                <cfoutput>
                    <h3 style="
                        font-size: 28px;
                        color: ##1a1a1a;
                        margin: 15px 0;
                        font-weight: bold;
                    ">
                        #certificate.courseName#
                    </h3>
                </cfoutput>
                
                <!--- Course Details --->
                <cfoutput>
                    <p style="font-size: 14px; color: ##666; margin: 5px 0 30px 0;">
                        (#certificate.courseHours# hours | Completed on #dateFormat(certificate.completionDate, "mmmm d, yyyy")#)
                    </p>
                </cfoutput>
                
                <!--- Signature Section --->
                <table width="100%" style="margin-top: 60px;">
                    <tr>
                        <td style="width: 50%; text-align: center; vertical-align: bottom;">
                            <div style="
                                border-top: 2px solid ##333;
                                width: 60%;
                                margin: 0 auto 10px auto;
                            "></div>
                            <cfoutput>
                                <p style="font-size: 14px; color: ##333; margin: 0; font-weight: bold;">
                                    #certificate.instructorName#
                                </p>
                                <p style="font-size: 12px; color: ##666; margin: 5px 0 0 0;">
                                    Course Instructor
                                </p>
                            </cfoutput>
                        </td>
                        <td style="width: 50%; text-align: center; vertical-align: bottom;">
                            <div style="
                                border-top: 2px solid ##333;
                                width: 60%;
                                margin: 0 auto 10px auto;
                            "></div>
                            <cfoutput>
                                <p style="font-size: 14px; color: ##333; margin: 0; font-weight: bold;">
                                    #dateFormat(certificate.issueDate, "mmmm d, yyyy")#
                                </p>
                                <p style="font-size: 12px; color: ##666; margin: 5px 0 0 0;">
                                    Date Issued
                                </p>
                            </cfoutput>
                        </td>
                    </tr>
                </table>
                
                <!--- Certificate Number (bottom right) --->
                <cfoutput>
                    <div style="
                        position: absolute;
                        bottom: 20px;
                        right: 40px;
                        font-size: 10px;
                        color: ##999;
                    ">
                        Certificate No: #certificate.certificateNumber#
                    </div>
                </cfoutput>
                
            </div>
        </div>
    </div>
    
</cfdocument>

<p><strong>✓ Certificate PDF generated successfully!</strong></p>
<p>The certificate features a professional landscape layout with elegant styling.</p>

<hr>

<h2>Example 2: Batch Generate Certificates</h2>

<cfscript>
    // Multiple students who completed a course
    completedStudents = [
        {name: "Sarah Johnson", completionDate: createDate(2024, 11, 1)},
        {name: "Michael Brown", completionDate: createDate(2024, 11, 3)},
        {name: "Emily Davis", completionDate: createDate(2024, 11, 5)}
    ];
    
    courseName = "Introduction to Web Development";
    instructorName = "Prof. Amanda Lee";
</cfscript>

<p><strong>Generating certificates for <cfoutput>#arrayLen(completedStudents)#</cfoutput> students...</strong></p>

<cfloop array="#completedStudents#" index="student">
    <cfset certNumber = "CERT-" & year(now()) & "-" & randRange(10000, 99999)>
    
    <cfdocument format="pdf" filename="#expandPath('./')#certificate_#replace(student.name, ' ', '_', 'ALL')#.pdf" overwrite="true">
        
        <div style="
            width: 100%;
            min-height: 600px;
            background-color: ##f5f5f5;
            font-family: Arial, sans-serif;
            padding: 40px;
            text-align: center;
        ">
            
            <div style="
                background-color: white;
                border: 5px solid ##0066cc;
                padding: 40px;
                border-radius: 15px;
            ">
                
                <h1 style="color: ##0066cc; font-size: 36px;">Certificate of Completion</h1>
                
                <p style="font-size: 14px; color: ##666; margin: 20px 0;">This certifies that</p>
                
                <cfoutput>
                    <h2 style="font-size: 32px; color: ##333; margin: 15px 0;">#student.name#</h2>
                </cfoutput>
                
                <p style="font-size: 14px; color: ##666;">has successfully completed</p>
                
                <cfoutput>
                    <h3 style="font-size: 24px; color: ##0066cc; margin: 15px 0;">#courseName#</h3>
                </cfoutput>
                
                <cfoutput>
                    <p style="font-size: 14px; color: ##666; margin: 30px 0;">
                        Completion Date: #dateFormat(student.completionDate, "mmmm d, yyyy")#
                    </p>
                </cfoutput>
                
                <div style="margin-top: 50px;">
                    <div style="display: inline-block; width: 200px; border-top: 2px solid ##333;">
                        <cfoutput>
                            <p style="margin: 10px 0 0 0; font-size: 12px;">#instructorName#</p>
                            <p style="margin: 0; font-size: 10px; color: ##666;">Instructor</p>
                        </cfoutput>
                    </div>
                </div>
                
                <cfoutput>
                    <p style="font-size: 9px; color: ##999; margin-top: 40px;">Certificate No: #certNumber#</p>
                </cfoutput>
                
            </div>
        </div>
        
    </cfdocument>
    
    <cfoutput>
        <p>✓ Generated: certificate_#replace(student.name, " ", "_", "ALL")#.pdf</p>
    </cfoutput>
</cfloop>

<p><strong>Batch generation complete!</strong> All certificates have been saved to the current directory.</p>

<hr>

Service agreement and contract management

Your business needs to generate service agreements, contracts, and legal documents automatically when customers sign up for services. These documents must include terms, conditions, pricing, signatures, and be legally compliant. PDFs ensure documents can't be easily altered after generation.
Problem statement
  • Need to generate legal contracts automatically
  • Must include company and customer information
  • Require terms and conditions, pricing, and signatures
  • Need to save copies for legal compliance
  • Should include unique contract numbers for tracking
Solution
The cfdocument tag generates contract-quality PDFs, instantly creates contracts upon signup, or personalizes the PDF with customer data.
<h1>Contract/Agreement Generator Demo</h1>

<p><strong>What This Demo Shows:</strong> How to use cfdocument to generate professional contracts and service agreements.</p>
<hr>

<cfscript>
    // Contract data
    contract = {
        contractNumber: "SA-" & year(now()) & "-" & randRange(1000, 9999),
        effectiveDate: now(),
        expirationDate: dateAdd("y", 1, now()),
        
        // Service provider (company)
        provider: {
            name: "TechServices Inc.",
            address: "123 Business Plaza",
            city: "San Francisco, CA 94102",
            phone: "(555) 123-4567",
            email: "contracts@techservices.com"
        },
        
        // Client information
        client: {
            name: "John Smith",
            company: "Acme Corporation",
            address: "456 Client Street",
            city: "New York, NY 10001",
            phone: "(555) 987-6543",
            email: "john.smith@acme.com"
        },
        
        // Service details
        service: {
            name: "Premium Cloud Hosting",
            description: "24/7 managed cloud hosting with 99.9% uptime guarantee",
            monthlyFee: 299.99,
            setupFee: 499.99,
            billingCycle: "Monthly"
        }
    };
</cfscript>

<h2>Generate Service Agreement PDF</h2>

<cfdocument format="pdf" pageType="letter" orientation="portrait"
    margintop="1" marginbottom="1" marginleft="1" marginright="1">
    
    <!--- Header --->
    <cfdocumentitem type="header">
        <table width="100%" style="border-bottom: 1px solid ##333; padding-bottom: 5px;">
            <tr>
                <td style="font-size: 10px; font-weight: bold;">
                    <cfoutput>SERVICE AGREEMENT - #contract.contractNumber#</cfoutput>
                </td>
                <td style="text-align: right; font-size: 9px;">
                    <cfoutput>Page #cfdocument.currentpagenumber# of #cfdocument.totalpagecount#</cfoutput>
                </td>
            </tr>
        </table>
    </cfdocumentitem>
    
    <!--- Footer --->
    <cfdocumentitem type="footer">
        <p style="font-size: 8px; color: ##666; text-align: center; border-top: 1px solid ##ccc; padding-top: 5px;">
            <cfoutput>
                This is a legally binding agreement. Contract ##: #contract.contractNumber# | Generated: #dateFormat(now(), "mm/dd/yyyy")#
            </cfoutput>
        </p>
    </cfdocumentitem>
    
    <!--- Contract Content --->
    <div style="font-family: Times New Roman, serif; font-size: 12px;">
        
        <!--- Title --->
        <h1 style="text-align: center; font-size: 20px; margin: 20px 0;">SERVICE AGREEMENT</h1>
        
        <cfoutput>
            <p style="text-align: center; font-size: 11px; margin: 5px 0;">
                Contract Number: #contract.contractNumber#
            </p>
            <p style="text-align: center; font-size: 11px; margin: 5px 0 30px 0;">
                Effective Date: #dateFormat(contract.effectiveDate, "mmmm d, yyyy")#
            </p>
        </cfoutput>
        
        <!--- Parties Section --->
        <p style="font-weight: bold; margin-top: 20px;">THIS AGREEMENT is entered into as of the date specified above between:</p>
        
        <table width="100%" style="margin: 20px 0;" cellpadding="10">
            <tr>
                <td style="width: 50%; vertical-align: top; border: 1px solid ##ddd; background-color: ##f9f9f9;">
                    <p style="font-weight: bold;">SERVICE PROVIDER:</p>
                    <cfoutput>
                        <p>#contract.provider.name#<br>
                        #contract.provider.address#<br>
                        #contract.provider.city#<br>
                        Phone: #contract.provider.phone#<br>
                        Email: #contract.provider.email#</p>
                    </cfoutput>
                </td>
                <td style="width: 50%; vertical-align: top; border: 1px solid ##ddd; background-color: ##f9f9f9;">
                    <p style="font-weight: bold;">CLIENT:</p>
                    <cfoutput>
                        <p>#contract.client.name#<br>
                        #contract.client.company#<br>
                        #contract.client.address#<br>
                        #contract.client.city#<br>
                        Phone: #contract.client.phone#<br>
                        Email: #contract.client.email#</p>
                    </cfoutput>
                </td>
            </tr>
        </table>
        
        <!--- Services Section --->
        <h2 style="font-size: 14px; border-bottom: 2px solid ##333; padding-bottom: 5px;">1. SERVICES PROVIDED</h2>
        
        <cfoutput>
            <p><strong>Service Name:</strong> #contract.service.name#</p>
            <p><strong>Description:</strong> #contract.service.description#</p>
        </cfoutput>
        
        <!--- Term Section --->
        <h2 style="font-size: 14px; border-bottom: 2px solid ##333; padding-bottom: 5px; margin-top: 20px;">2. TERM</h2>
        
        <cfoutput>
            <p>This Agreement shall commence on #dateFormat(contract.effectiveDate, "mmmm d, yyyy")# and shall continue for a period of one (1) year, expiring on #dateFormat(contract.expirationDate, "mmmm d, yyyy")#, unless earlier terminated as provided herein.</p>
        </cfoutput>
        
        <!--- Fees Section --->
        <h2 style="font-size: 14px; border-bottom: 2px solid ##333; padding-bottom: 5px; margin-top: 20px;">3. FEES AND PAYMENT</h2>
        
        <cfoutput>
            <p><strong>Setup Fee:</strong> $#numberFormat(contract.service.setupFee, "0,000.00")# (one-time, due upon signing)</p>
            <p><strong>Monthly Service Fee:</strong> $#numberFormat(contract.service.monthlyFee, "0,000.00")#</p>
            <p><strong>Billing Cycle:</strong> #contract.service.billingCycle#</p>
        </cfoutput>
        
        <p>Payment is due within fifteen (15) days of invoice date. Late payments may incur a 1.5% monthly interest charge.</p>
        
        <!--- Terms and Conditions --->
        <h2 style="font-size: 14px; border-bottom: 2px solid ##333; padding-bottom: 5px; margin-top: 20px;">4. TERMS AND CONDITIONS</h2>
        
        <p><strong>4.1 Service Availability:</strong> Provider agrees to use commercially reasonable efforts to maintain 99.9% uptime for the services.</p>
        
        <p><strong>4.2 Client Responsibilities:</strong> Client agrees to provide accurate information and maintain security of account credentials.</p>
        
        <p><strong>4.3 Confidentiality:</strong> Both parties agree to maintain confidentiality of proprietary information shared during the term of this agreement.</p>
        
        <p><strong>4.4 Termination:</strong> Either party may terminate this agreement with thirty (30) days written notice. Early termination fees may apply.</p>
        
        <!--- Page Break --->
        <cfdocumentitem type="pagebreak" />
        
        <!--- Signatures Section --->
        <h2 style="font-size: 14px; border-bottom: 2px solid ##333; padding-bottom: 5px; margin-top: 20px;">5. ACCEPTANCE AND SIGNATURES</h2>
        
        <p>By signing below, both parties acknowledge that they have read, understood, and agree to be bound by the terms and conditions of this Agreement.</p>
        
        <table width="100%" style="margin-top: 60px;">
            <tr>
                <td style="width: 50%; padding-right: 20px;">
                    <div style="border-top: 2px solid ##333; margin-bottom: 10px;"></div>
                    <cfoutput>
                        <p style="margin: 0;"><strong>Provider Signature</strong></p>
                        <p style="margin: 5px 0 0 0; font-size: 11px;">#contract.provider.name#</p>
                        <p style="margin: 5px 0 0 0; font-size: 11px;">Date: ____________________</p>
                    </cfoutput>
                </td>
                <td style="width: 50%; padding-left: 20px;">
                    <div style="border-top: 2px solid ##333; margin-bottom: 10px;"></div>
                    <cfoutput>
                        <p style="margin: 0;"><strong>Client Signature</strong></p>
                        <p style="margin: 5px 0 0 0; font-size: 11px;">#contract.client.name#</p>
                        <p style="margin: 5px 0 0 0; font-size: 11px;">Date: ____________________</p>
                    </cfoutput>
                </td>
            </tr>
        </table>
        
        <!--- Legal Notice --->
        <div style="margin-top: 60px; padding: 15px; background-color: ##f5f5f5; border: 1px solid ##ddd;">
            <p style="font-size: 10px; margin: 0;">
                <strong>LEGAL NOTICE:</strong> This is a legally binding agreement. If you do not understand any provision of this agreement, please consult with legal counsel before signing.
            </p>
        </div>
        
    </div>
    
</cfdocument>

<p><strong>✓ Service agreement PDF generated successfully!</strong></p>
<p>The contract is ready for review and signatures.</p>

<hr>

More like this

  • Differences between cfdocument and cfhtmltopdf

Share this page

Was this page helpful?
We're glad. Tell us how this page helped.
We're sorry. Can you tell us what didn't work for you?
Thank you for your feedback. Your response will help improve this page.

On this page