You can specify a ColdFusion image as a watermark. You can extract an image from a database and manipulate the image in memory, but you don't have to write the manipulated image to a file. Instead, you can apply the manipulated image as a watermark in a PDF document.
In the following example, the first ColdFusion page extracts images from a database and populates a pop-up menu with the titles of the artwork:
<!--- Create a query to extract artwork from the cfartgallery database. ---> <cfquery name="artwork" datasource="cfartgallery"> SELECT ARTID, ARTNAME, LARGEIMAGE FROM ART ORDER BY ARTNAME </cfquery> <!--- Create a form that lists the artwork titles generated by the query. Set the value to LARGEIMAGE so that the image file is passed to the processing page. ---> <cfform action="addWatermarkB.cfm" method="post"> <p>Please choose a title:</p> <cfselect name="art" query="artwork" display="ARTNAME" value="LARGEIMAGE" required="yes" multiple="no" size="8"> </cfselect> <br/> <cfinput type="submit" name="submit" value="OK"> </cfform>
The action page generates a ColdFusion image from the selected file by using the cfimage tag. The ImageScaleToFit function resizes the image and applies the bicubic interpolation method to improve the resolution. To use the manipulated image as a watermark, specify the image variable, as the following example shows:
<!--- Verify that an image file exists and is in a valid format. ---> <cfif IsImageFile("../cfdocs/images/artgallery/#form.art#")> <!--- Use the cfimage tag to create a ColdFusion image from the file chosen from the list. ---> <cfimage source="../cfdocs/images/artgallery/#form.art#" action="read" name="myWatermark"> <!--- Use the ImageScaleToFit function to resize the image by using the bicubic interpolation method for better resolution. ---> <cfset ImageScaleToFit(myWatermark,450,450,"bicubic")> <!--- Use the ColdFusion image variable as the watermark in a PDF document. ---> <cfpdf action="addWatermark" source="title.pdf" image="#myWatermark#" destination="watermarkTitle.pdf" overwrite="yes"> <cfelse> <p>I'm sorry, no image exists for that title. Please click the Back button and try again.</p> </cfif>
For more information on ColdFusion images, see Creating and Manipulating ColdFusion Images.