0

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?

Mike Causer
  • 8,196
  • 2
  • 43
  • 63
Tom Hubbard
  • 15,820
  • 14
  • 59
  • 86

1 Answers1

1

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#" />
Matt Shooks
  • 1,002
  • 7
  • 9
  • Thanks. I would like to get it into a CFPDF variable though so that I can do some of the CFPDF actions on it as well. – Tom Hubbard Feb 21 '11 at 19:47
  • Gotcha, if you don't want to stick it on your web server file system and you have ColdFusion 9 you can use the CF virtual file system and store the files in memory instead using ram:// – Matt Shooks Feb 21 '11 at 20:23