dynamic pdf-cfdocument + cfcontent + image + email attachement

别说谁变了你拦得住时间么 提交于 2019-12-09 03:23:26

问题


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 need 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.


回答1:


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>



回答2:


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.



来源:https://stackoverflow.com/questions/4813587/dynamic-pdf-cfdocument-cfcontent-image-email-attachement

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