Created
November 21, 2014 15:34
-
-
Save cflove/57250b9d51705a8dd656 to your computer and use it in GitHub Desktop.
Fetch list of columns and their values for Railo CFM. Not complete, just enough functionality for my current use.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfcomponent displayname = "PDFTools" output= "Yes" accessors="true" > | |
<cfproperty name="file"> | |
<cfproperty name="map"> | |
<cffunction name = "init" access = "Public" output = "No" returntype = "Any"> | |
<cfargument name = "filePath" required= "Yes" type = "String" default = "" /> | |
<cfset local.p = createObject("java",'org.apache.pdfbox.pdmodel.PDDocument') /> | |
<cfset COSName = createObject("java",'org.apache.pdfbox.cos.COSName') /> | |
<cfset setFile( local.p.load( arguments.filePath ) )/> | |
<cfreturn this> | |
</cffunction> | |
<!--- ************************************************************************ ---> | |
<!--- loop though the pages and get all annotations into an HashMap array ---> | |
<!--- ************************************************************************ ---> | |
<cffunction name = "GetAnotations" access= "Private" output = "No" returntype="void"> | |
<cfset setMap( createObject('java','java.util.HashMap').init() ) /> | |
<cfset local.thispage = 1 /> | |
<cfloop array = "#getFile().getDocumentCatalog().getAllPages()#" index = "local.page"> | |
<!--- loop though annotations ---> | |
<cfloop array="#local.page.getAnnotations()#" index="local.a"> | |
<cfset getMap().put( local.a.getDictionary() , local.thispage) /> | |
</cfloop> | |
<cfset local.thispage = 1+local.thispage /> | |
</cfloop> | |
</cffunction> | |
<!--- ************************************************************************ ---> | |
<!--- Read Form Values ---> | |
<!--- ************************************************************************ ---> | |
<cffunction name = "FetchFeidls" access= "Public" output = "Yes" returntype= "Any"> | |
<cfset GetAnotations() /> | |
<cfset local.r = FetchFeidlsLoop( getFile().getDocumentCatalog().getAcroForm().getFields(), [] ) /> | |
<cfreturn local.r> | |
</cffunction> | |
<cffunction name = "FetchFeidlsLoop" access= "Private" output = "Yes" returntype= "Any"> | |
<cfargument name= "fields" required= "No" type= "Any" default= "" /> | |
<cfargument name= "returns" required= "No" type= "Any" default= "" /> | |
<cfargument name= "break" required= "No" type= "Any" default= "1" /> | |
<cfloop array = "#arguments.fields#" index = "local.i"> | |
<cfif isArray(local.i.getKids())> | |
<cfset arguments.break = 1+arguments.break /> | |
<cfif arguments.break lt 1000> | |
<!--- call the function self, we need to loop until all done ---> | |
<cfset FetchFeidlsLoop( i.getKids(), arguments.returns , arguments.break ) /> | |
</cfif> | |
<cfelse> | |
<cfset local.field = {}> | |
<cfif not isNull(local.i.getValue())> | |
<cfset local.field.value = local.i.getValue() /> | |
</cfif> | |
<cfif not isNull(local.i.getAlternateFieldName())> | |
<cfset local.field.ToolTip = local.i.getAlternateFieldName() /> | |
</cfif> | |
<cfset local.field.Name = local.i.getFullyQualifiedName() /> | |
<cfset local.class = listLast( i.class.toString() , '.') /> | |
<cfset local.field.position = arrayToList( local.i.getDictionary().getDictionaryObject( COSName.RECT ).toFloatArray(),' ') /> | |
<cfset local.field.page = getMap().get( i.getDictionary() ) /> | |
<cfswitch expression = "#local.class#"> | |
<cfcase value = "PDTextbox"> | |
<cfset local.field.Type = 'TextBox' /> | |
</cfcase> | |
<cfcase value = "PDCheckbox"> | |
<cfset local.field.Type = 'CheckBox' /> | |
<cfif not isNull(local.i.getOnValue())> | |
<cfset local.field.value = local.i.getOnValue() /> | |
</cfif> | |
<cfset local.field.isChecked = local.i.isChecked() /> | |
</cfcase> | |
<!--- handle radio buttons and buttons later ----> | |
</cfswitch> | |
<!--- remove NULL form end of field name ----> | |
<cfif listLast(local.field.Name,'.') eq 'NULL'> | |
<cfset local.field.Name = listDeleteAt( local.field.Name , listlen(local.field.Name,'.'), '.')> | |
</cfif> | |
<cfset arrayAppend(arguments.returns,local.field) /> | |
</cfif> | |
</cfloop> | |
<cfreturn arguments.returns> | |
</cffunction> | |
</cfcomponent> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment