5

Can cfpdf read a binary database column directly?

I currently have it where I run a query to get the column.

Use cffile to write the file to a directory

Then read with cfpdf so I can extracttext.

Is it possible to do this without the cffile write and read the binary file directly?

If so, could I get an example.

E Paiz
  • 661
  • 4
  • 9
  • 19

3 Answers3

3

What version are you using? The following worked for me with CF9 / MS SQL (varbinary column)

<cfquery name="getPdf" ....>
    SELECT Data 
    FROM   someTable
    WHERE  ID = 123
</cfquery>

<cfset pdfBinary = getPdf.data[1]>
<cfpdf action="extractText" source="pdfBinary" name="result">
<cfdump var="#result#">

Edit: To clarify, cfpdf complains when you use queryName.columnName as the "source". I suspect cfpdf sees it as a query column object instead of automatically grabbing the value in the query's first row ie queryName.columnName[ 1 ]. The work-around is to create a reference to it, and use the other variable instead.

Leigh
  • 28,765
  • 10
  • 55
  • 103
  • Thanks Leigh, this did work and is exactly what I was looking for. Although anyone reading this thread I would encourage to read the RAM file storage discussion below – E Paiz May 21 '12 at 21:58
  • For larger pdfs/blobs, it might be worth experimenting with both methods to see if VFS offers any improvement. – Leigh May 21 '12 at 22:38
  • Any idea on what could be done for CF 8? extractText is not a valid option in that version. – Limey Jun 21 '12 at 22:08
  • You can extract text with `processddx`.. but it requires a physical file path. That is the only simple option I am aware of for CF8. – Leigh Jun 21 '12 at 22:14
  • @Leigh I found a CF8 friendly version and posted it as answer. – Limey Jun 21 '12 at 22:39
  • @Limey - Oh sorry - I thought you were asking how to extract text with CF8, like Eric. Generating a download from binary is totally different :) – Leigh Jun 21 '12 at 22:42
1

I'm not 100% sure, but you should be able to do something like this:

<cfset myPDF = binaryEncode(binaryData,'base64')>

<cfpdf action="read" source="myPDF" name="PDFObj">
Josh Siok
  • 936
  • 4
  • 8
  • 2
    Another idea would be to write it to the RAM disk using cffile. This would provide better performance and eliminate writing to disk. http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSe9cbe5cf462523a0-70e2363b121825b20e7-8000.html – Josh Siok May 21 '12 at 19:22
  • I was able to get the In memory to work using the examples in the link provided by Josh. FYI, the documentation says cfpdf is not supported. Although, that is exactly what I used and it appears to be working. *** Point of caution. If you are not removing your files from RAM you could eventually eat up all of your allocated space and force a crash – E Paiz May 21 '12 at 21:44
0

I found a simple way to do this:

<cfheader name="Content-Disposition" value="inline; filename=test.pdf">
<cfcontent type="application/pdf" variable="#qGetFile.uploaded_file#">

This was already in the code I inherited, but it was never working. I found the problem was the datasource and not the code; it was not set to accept BLOBs.

Limey
  • 2,642
  • 6
  • 37
  • 62