Note: Adobe recommends that you use the BinaryDecode function to convert Base64 encoded data to binary data in all new applications. |
Description
Calculates the binary representation of Base64-encoded data, PDF document, or a spreadsheet.
A binary representation of the data.
Conversion functions, String functions
ToBinary(Data)
See also
Parameter |
Description |
|---|---|
Data |
A variable representing data in Base64-encoded format or a PDF document. |
The ToBinary function can take as a parameter a PDF document variable (specified by the cfpdf tag name attribute). In this case, the ToBinary function returns a byte array (byte[]) representation of the document. You can use the results of this function, for example, to store the PDF in a database as a BLOB, or, in a cfcontent tag, to write the PDF to the browser. You can use this binary representation with a read operation in the cfpdf tag to create a variable.The following example reads an unprotected PDF file, applies protections, and displays it in the browser:
<cfpdf action="read" source="Copy of coldfusion11.pdf" name="p"> <cfpdf action="protect" source="p" newUserpassword="user" permissions="none" newOwnerpassword="owner"> <cfcontent type="application/pdf" variable="#tobinary(p)#">
Adobe recommends that you use the BinaryDecode function to convert Base64 encoded data to binary data in all new applications.If you pass a binary value to this function, it returns the input value.
<cfscript>
strValue = "Sgt. Pepper's Lonely Hearts Club Band"
strBase64Value = ToBase64(strValue)
strNewValue = ToString(ToBinary(strBase64Value))
writeOutput("Base 64 is: " & strBase64Value & "<br/>") // U2d0LiBQZXBwZXIncyBMb25lbHkgSGVhcnRzIENsdWIgQmFuZA==
writeOutput("Binary value is: " & strNewValue) // Sgt. Pepper's Lonely Hearts Club Band
</cfscript>
Sign in to your account