开发者

dynamic pdf-cfdocument + cfcontent + image + email attachement

How can images be loaded into a dynamically generated pdf (cfdocument)? In that the pdf is not stored the hdd. The pdf needs to be emailed, and the ram cleared. The images are stored outside of the wwwroot folder. If it is need be, the pdf can get stored in the hdd, get attached, emailed, then deleted, but would opt for it not to get stored in the hdd.

c:\coldFusion9\imgs\ is the dir

Sample:

<cfdocument format="PDF" localurl="true">
<cfoutput> #vars#</cfoutput>
</cfdocument>

I have used

<img src="">

inside cfdocument, and it works if the image is in the wwwroot (http...) folder, but not when the image is outsite the wwwroot ("c:\coldFusion9\imgs#image#.png" or "../imgs/#image#.png").

I suppose that cfcontent is ideal

So, inside cfdocument, I do this:

<cffile action="readbinary" file="c:\coldFusion9\imgs\#image#.png" variable="img">
<cfcontent type="image/jpg" variable="#img#" > 

The result is that the image loads, on the screen, not the pdf.

Would like to email the pdf as an email attachement. The pdf does not nee开发者_JAVA百科d to render on screen, but for testing purposes, we could let it render on the screen to know if the image was loaded or not, by either naming or not naming the cfdocument. The pdf renders when the name is removed, it does not render when the name is present.

Appreciate your help.


If i understand your question correctly. You want to 1. Grab an image from a folder outside of your webroot 2. Place image in a cfdocument 3. Attach cfdocument to a cfmail

if that's is the case you need cfimage instead of img and the rest you can find on Ben Nadel's site http://www.bennadel.com/blog/1700-Ask-Ben-Creating-A-PDF-And-Attaching-It-To-An-Email-Using-ColdFusion.htm

or expand on the snippet below.

<cfdocument format="pdf" name="mydoc">

    <cfimage action="writeTobrowser" source="c:\temp\test.png" >

</cfdocument>

<cfmail
    from="x@y.com"
    to="y@x.com"
    subject="this is it">
    <cfmailparam
        file="mydoc.pdf"
        type="application/pdf"
        content="#mydoc#"/>
</cfmail>


A couple notes to clarify:

cfdocument uses an HTTP connection to grab images, which is why you can't grab any outside the webroot. In my experience, relative paths are problematic, so it's best to use absolute paths. If you want to use images from outside the webroot, you'll need to provide them directly, as in your example or as @KobbyPemson did.

The reason that you don't see the PDF when you add a name is that the name attribute does not name the PDF. It is the name of the variable in which the PDF is stored. So, when you provide it, you are telling CF to stuff the PDF in a variable using the name you supply.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜