-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbase_pdf_generator.cfc
71 lines (54 loc) · 1.74 KB
/
base_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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
component {
public component function init(string orientation = 'Portrait'
, struct margins = {}
, string pageType = 'Letter'
, numeric executeTimeout = 30
, struct addlOptions = {}){
variables.body_parts = [];
for( var key in ['orientation', 'margins', 'pageType', 'executeTimeout', 'addlOptions'] ){
variables[key] = arguments[key];
}
return this;
}
public void function appendPageBreakToBody(){
ArrayAppend(variables.body_parts, '<div style="page-break-after:always; display: block; clear: both;"></div>');
}
public void function appendToBody(required string html){
ArrayAppend(variables.body_parts, cleanHTML(arguments.html));
}
public void function generate(){
//PDF Generation
}
public void function setHeader(required string headerHTML){
variables.headerHTML = arguments.headerHTML;
}
public void function setFooter(required string footerHTML){
variables.footerHTML = arguments.footerHTML;
}
private string function cleanHTML(required string html){
var clean = Replace(arguments.html, '†', '†', 'all');
return clean;
}
private string function getFooter(){
return replaceDocumentVars(variables.footerHTML);
}
private string function getHeader(){
return replaceDocumentVars(variables.headerHTML);
}
private string function replaceDocumentVars(required string html){
var htmlInProgress = arguments.html;
var varMap = documentVariableMapping();
for( var key in varMap ){
htmlInProgress = ReplaceNoCase(htmlInProgress, key, varMap[key], 'all');
}
return htmlInProgress;
}
private struct function documentVariableMapping(){
/*
return { '$currentPageNumber$' = '[page]'
, '$totalPageCount$' = '[topage]'};
*/
throw(type="unimplementedFunction",
message="This function needs to be implemented by children classes");
}
}