I have multiple pdfs stored in my database as blobs and I need to merge them to create a single pdf that needs to be streamed to the user.
I understand that it is fairly easy to do this if I am rendering a single pdf from blob, but I cannot figure how to merge multiple blobs.
<cfheader name="Content-Disposition" value="inline; filename=#document.name#.#document.ext#">
<cfcontent type="application/pdf" variable="#document.content#">
I see that CFPDF helps with this functionality, but cant seem to be able to get my blob into a cfpdf variable. A similar question has been asked here before, but it doesnt have the answer I seek.
Thanks!
Try converting the blob data to a file (in-memory using ram://
if possible to save writing to disk) and then use that as the cfpdf
merge source. You can do it for each blob as you loop over your query within the cfpdf action="merge"
tag:
<cfquery name="q" datasource="test">
SELECT content FROM pdfs
</cfquery>
<cfpdf action="merge" name="mergedPdf">
<cfloop query="q">
<cfset tempBinary=q.content><!---intermediate var seems to be necessary in some environments --->
<cffile action="write" output="#tempBinary#" file="ram://temp.pdf">
<cfpdfparam source="ram://temp.pdf">
</cfloop>
</cfpdf>
<cfcontent type="application/pdf" variable="#ToBinary( mergedPdf )#" reset="true">
Note you can use a single temp file - no need to create a different one for each blob in the query.