-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpdfMaker.cfc
More file actions
146 lines (115 loc) · 5.59 KB
/
pdfMaker.cfc
File metadata and controls
146 lines (115 loc) · 5.59 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<!---
Author : YaNnIcK MoRiN
Find me at : Google+, Github or at the beach.
--->
<cfcomponent output="false" mixin="controller">
<cffunction name="init">
<cfset this.version = "1.1.4">
<cfreturn this>
</cffunction>
<cffunction name="createPDF" hint="Hummmm....I think I will create a PDF today!!!">
<cfargument name="doctype" type="string" default="partial" required="false" hint="choose the type of content to print to the pdf. You can choose between : partial | url | text.">
<cfargument name="partial" type="any" required="false"
hint="The name of the partial file to be used for the content. ONLY if you have selected type(partial)">
<cfargument name="url" type="string" required="false"
hint="The url to grab for the document content. Default is the current page. ONLY if you have selected type(url).">
<cfargument name="text" type="string" required="false"
hint="The text to grab for the document content. ONLY if you have selected type(text).">
<cfargument name="sendToFile" type="string" required="false" default="browser"
hint="Save to file. Otherwise send to browser">
<cfargument name="pathTofilename" type="string" required="false"
hint="Path to the filename. By default its /files. ONLY if you have selected sendToFile(true)">
<cfargument name="filename" type="string" required="false" default="browser"
hint="Name of a file to contain the PDF. ONLY if you have selected sendToFile(true)">
<cfargument name="overwrite" type="boolean" required="false" default="false"
hint="Specifies whether we should overwrites an existing file. Used in conjunction with the filename attribute. ONLY if you have selected sendToFile(true)">
<cfargument name="orientation" type="string" required="false" default="portrait"
hint="Page orientation: portrait | landscape">
<cfargument name="footer" type="string" required="false" default=""
hint="Text to add to the footer">
<cfargument name="header" type="string" required="false" default=""
hint="Text to add to the header">
<cfset var loc = {}>
<cfset loc.thisPath = ExpandPath("*.*")>
<cfset loc.thisDirectory = GetDirectoryFromPath(loc.thisPath)>
<cfset loc.filename = "browser">
<cfset loc.document = "">
<cfset docheader = arguments.header>
<cfset docfooter = arguments.footer>
<cfset loc.pathToFilename = loc.thisDirectory & application.wheels.filePath>
<cfif StructKeyExists(arguments, "filename")>
<cfset loc.filename = arguments.filename>
</cfif>
<!--- Get the document to print to pdf --->
<cfif arguments.doctype EQ "partial" AND arguments.partial NEQ "">
<cfif arguments.sendToFile EQ "true">
<cfdocument format="pdf" filename="#loc.pathToFilename#/#loc.filename#.pdf" overwrite="#arguments.overwrite#" orientation="#arguments.orientation#">
<cfoutput>
<cfdocumentitem type="header">#docheader#</cfdocumentitem>
<cfset c=0>
<cfloop list="#arguments.partial#" index="i">
<cfset c=c+1>
<cfoutput>#includePartial("#i#")#</cfoutput>
<cfif listLen(arguments.partial) NEQ c>
<cfdocumentitem type="pagebreak"/>
</cfif>
</cfloop>
<cfdocumentitem type="footer">#docfooter#</cfdocumentitem>
</cfoutput>
</cfdocument>
<cfelse><!--- Send to browser --->
<cfdocument format="pdf" orientation="#arguments.orientation#">
<cfoutput>
<cfdocumentitem type="header">#docheader#</cfdocumentitem>
<cfset c=0>
<cfloop list="#arguments.partial#" index="i">
<cfset c=c+1>
<cfoutput>#includePartial("#i#")#</cfoutput>
<cfif listLen(arguments.partial) NEQ c>
<cfdocumentitem type="pagebreak"/>
</cfif>
</cfloop>
<cfdocumentitem type="footer">#docfooter#</cfdocumentitem>
</cfoutput>
</cfdocument>
</cfif>
<cfelseif arguments.doctype EQ "url">
<cfif arguments.url EQ "">
<cfhttp url="#GetCurrentURL()#" method="get" resolveURL="true">
<cfelse>
<cfhttp url="#arguments.url#" method="get" resolveURL="true">
</cfif>
<cfset loc.document = cfhttp.filecontent>
<cfif arguments.sendToFile EQ "true">
<cfdocument format="pdf" filename="#loc.pathToFilename#/#loc.filename#.pdf" overwrite="#arguments.overwrite#" orientation="#arguments.orientation#">
<cfoutput>#loc.document#</cfoutput>
</cfdocument>
<cfelse><!--- Send to browser --->
<cfdocument format="pdf" orientation="#arguments.orientation#">
<cfoutput>#loc.document#</cfoutput>
</cfdocument>
</cfif>
<cfelseif arguments.doctype EQ "text" AND arguments.text NEQ "">
<cfif arguments.sendToFile EQ "true">
<cfdocument format="pdf" filename="#loc.pathToFilename#/#loc.filename#.pdf" overwrite="#arguments.overwrite#" orientation="#arguments.orientation#">
<cfoutput>#loc.document#</cfoutput>
</cfdocument>
<cfelse><!--- Send to browser --->
<cfdocument format="pdf" orientation="#arguments.orientation#">
<cfoutput>#loc.document#</cfoutput>
</cfdocument>
</cfif>
</cfif>
</cffunction>
<cffunction name="GetCurrentURL" output="No" access="private">
<cfset var theURL = "http">
<cfif (cgi.https EQ "on" )><cfset theURL = "https"></cfif>
<cfset theURL = theURL & "://#cgi.server_name#">
<cfif cgi.server_port IS NOT 80 AND CGI.server_port IS NOT 443>
<cfset theURL = theURL & ":#cgi.server_port#">
</cfif>
<cfset theURL = theURL & getPageContext().getRequest().getRequestURI()>
<cfif len(cgi.query_string)><cfset theURL = theURL & "?#cgi.query_string#"></cfif>
<cfreturn theURL>
</cffunction>
</cfcomponent>