CFPDF create variable from a BLOB

1k views Asked by At

In ColdFusion 9 we have pdf data stored in a blob in the database.

How do I get that into a cfpdf variable? It seems like all options require a filename. Is there a way to do it without writing a file?

1

There are 1 answers

2
Matt Shooks On

CFPDF and CFDOCUMENT are for creating and modifying a PDF dynamically. As you already have the PDF in a blob in your database you simply need the CF page to send it back as part of the response using CFCONTENT. Assuming you are using some type of ID to reference which PDF you want to retrieve from your database an example would look like this:

<cfquery name="qryFile" datasource="MyDatasourceHere">
    SELECT id, name, data
    FROM files
    WHERE id = <cfqueryparam cfsqltype="cf_sql_integer" value="#URL.id#" />
</cfquery>
<cfheader name="content-length" value="#ArrayLen(qryFile.data)#" />
<cfheader name="content-disposition" value="attachment; filename=#qryFile.name#" />
<cfcontent type="application/octet-stream" variable="#qryFile.data#" />