Coldfusion CFPDF reading a binary database column

老子叫甜甜 提交于 2019-12-04 03:28:10

问题


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.


回答1:


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.




回答2:


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">



回答3:


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.



来源:https://stackoverflow.com/questions/10690548/coldfusion-cfpdf-reading-a-binary-database-column

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!