-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcfdocument_pdf_generator.cfc
51 lines (43 loc) · 1.21 KB
/
cfdocument_pdf_generator.cfc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<cfcomponent extends="base_pdf_generator">
<cfscript>
public void function appendPageBreakToBody(){
ArrayAppend(variables.body_parts, '<pagebreak>');
}
</cfscript>
<cffunction name="generate" returntype="void" output="true" access="public">
<cfdocument attributeCollection="#cfDocAttrs()#">
<cfif StructKeyExists(variables, 'headerHTML')>
<cfdocumentitem type="header">
#getHeader()#
</cfdocumentitem>
</cfif>
<cfif StructKeyExists(variables, 'footerHTML')>
<cfdocumentitem type="footer">
#getFooter()#
</cfdocumentitem>
</cfif>
<cfloop array="#variables.body_parts#" index="local.part">
<cfif part EQ '<pagebreak>'>
<cfdocumentitem type="pagebreak" />
<cfelse>
#part#
</cfif>
</cfloop>
</cfdocument>
</cffunction>
<cfscript>
private struct function cfDocAttrs(){
var attrs = { format = 'pdf'
, pagetype = variables.pagetype
, orientation = variables.orientation };
for( var key in variables.margins ){
attrs['margin#key#'] = variables.margins[key];
}
return attrs;
}
private struct function documentVariableMapping(){
return { '$currentPageNumber$' = cfdocument.currentpagenumber
, '$totalPageCount$' = cfdocument.totalpagecount };
}
</cfscript>
</cfcomponent>