To set up CF for the encryption
1. Download the latest binary of <a href="http://xml.apache.org/fop/download.html#binary">FOP</a> from apache.
2. Download the <a href="http://www.bouncycastle.org/download/jce-jdk13-124.jar ">Java Cryptography Extensions</a> (JCE) library extension from bouncy castle.
3. To the add java.security file in C:CFusionMX
untimejrelibsecurity the following line to the list of providers
security.provider.6=org.bouncycastle.jce.provider.BouncyCastleProvider
4. For a standalone installation place the following files in the C:CFusionMX
untimelib
- fop.jar
- Avalon-framework-cvs-20020806.jar
- batik.jar
- jce-jdk13-124.jar
5. In the CF administrator, under Java and JVM Settings add âC:CFusionMX
untimelibjce-jdk13-124.jar,C:CFusionMX
untimelibop.jar,â to the class path
6. Restart ColdFusion MX Application Server Service
<cfcomponent>
<!--- Initialize the FOP driver from xml.apache.org --->
<cfset THIS.fopdriver = CreateObject("java", "org.apache.fop.apps.Driver")>
<cfset THIS.lockname = CreateUUID()>
<cffunction name="ConvertFileToPDF" access="public">
<cfargument name="foFile" type="string" required="true">
<cfargument name="pdfFile" type="string" required="true">
<cfargument name="userPassword" type="string" required="true">
<!--- Set up Java input source --->
<cfset var input = CreateObject("java", "org.xml.sax.InputSource")>
<cfset input.init( ARGUMENTS.foFile)>
<!--- Proceed with PDF generation --->
<cfset private_generateEncryptedPDF(input, pdfFile, userPassword)>
</cffunction>
<cffunction name="ConvertStringToPDF" access="public">
<cfargument name="foString" type="string" required="true">
<cfargument name="pdfFile" type="string" required="true">
<cfargument name="userPassword" type="string" required="true">
<!--- Set up Java input source --->
<cfset var reader = CreateObject("java", "java.io.StringReader")>
<cfset var input = CreateObject("java", "org.xml.sax.InputSource")>
<cfset reader.init(foString)>
<cfset input.init(reader)>
<!--- Proceed with PDF generation --->
<cfset private_generateEncryptedPDF(input, pdfFile, userPassword)>
</cffunction>
<cffunction name="private_generateEncryptedPDF" access="private">
<cfargument name="input" type="any" required="true">
<cfargument name="pdfFile" type="string" required="true">
<cfargument name="userPassword" type="string" required="true">
<!--- Output stream for writing PDF file --->
<cfset var output = CreateObject("java", "java.io.FileOutputStream")>
<!--- Rendering options for encrypting PDF file --->
<cfset var rendererOptions = CreateObject("java","java.util.HashMap")>
<!--- Get ready to do the PDF generation --->
<cflock name="#THIS.lockname#" type="exclusive" timeout="10">
<cflock name="#ARGUMENTS.pdfFile#" type="exclusive" timeout="10">
<!--- Turn on the output stream --->
<cfset output.init( ARGUMENTS.pdfFile )>
<!--- Set the rendering options --->
<cfset rendererOptions.put("ownerPassword", "ownerpassword")>
<cfset rendererOptions.put("userPassword", "#userPassword#")>
<cfset rendererOptions.put("allowCopyContent", "FALSE")>
<cfset rendererOptions.put("allowEditContent", "FALSE")>
<cfset rendererOptions.put("allowPrint", "FALSE")>
<cfset rendererOptions.put("allowEditAnnonations", "False")>
<!--- Hook the FOP driver to the input/output --->
<cfset THIS.fopDriver.setInputSource(input)>
<cfset THIS.fopDriver.setOutputStream(output)>
<cfset THIS.fopDriver.setRenderer(THIS.fopDriver.RENDER_PDF)>
<cfset THIS.fopDriver.getRenderer().setOptions(rendererOptions)>
<!--- Perform the actual PDF generation --->
<cfset THIS.fopDriver.run()>
<!--- Turn off the output stream --->
<cfset output.close()>
</cflock>
</cflock>
</cffunction>
</cfcomponent>