Image Resizing Not Happening - coldfusion

Hey guys, I am trying to use a simple cfimage to resize a tmp image but its not working... am I doing it correctly?
<cfimage action="resize" height="300" source="#form.adminfileupload#" width="300" name="form.adminfileupload">
After it goes through that function I am trying to rename the tmp file. Is this the proper way to do this in ColdFusion?
Thanks

If you plan to save the data to the filesystem, use the "destination" attribute instead of the "name" attribute.
I've not tried resizing directly from an upload. You may need to use cffile to write a temp copy to a readable directory in order to provide a full filepath to cfimage.

Related

How to put an image from a local drive into a cfdocument file?

This will show me the image in a browser:
<cfset myImage=ImageNew("d:\UploadedDocuments\thumbnails\1487862_page_1.jpg")>
<cfimage source="#myImage#" action="writeToBrowser">
But if I use the same code inside of a .pdf file, it generates a small red x. Is this not possible to do?
If the image is already on the drive you don't need CFIMAGE here. You can embed it like so:
<img src="file:///d:\mysite\images\myimage.jpg" width="50" height="60">
You could also use an HTTP Path to it as well - store it at a location accessible by your web server through real or virtual directories use the <img> tag like you normally would.
This post on cfdocument and SSL and this suplimental post on using the file system with cfdocument should help you sort it out.

Cfdocument being served by server despite being in cfsavecontent

It seems that when I use the <cfsavecontent> tag, the output of that is being served by the server (without the variable being outputted), which, to me, kind of defeats the purpose of <cfsavecontent>.
If this is important: my application uses ColdSpring, ModelGlue and Transfer ORM.
Here's my example code in a function:
<cfsavecontent variable="testvar">
<cfinclude template="test.cfm" />
</cfsavecontent>
<cfreturn testvar>
And the template:
<cfdocument format="PDF" pagetype="A4" orientation="portrait" unit="cm">
<cfoutput>
<!--- PDF content here --->
</cfoutput>
</cfdocument>
The PDF content is being parsed by my browser (Google Chrome), while the view hasn't even been loaded in. How can I best prevent this from happening?
Just to clarify: I am not outputting the #testvar# variable yet in this code, though it seems it loads the template in the browser anyways.
To achieve what you're trying to do, should you not simply be using the name attribute of <cfdocument> to put the PDF data into a variable, instead of trying to <cfsavecontent> it?
Disclosure: I've never used <cfdocument> for anything other than proof-of-concept code and testing, but that's what I'm inferring from the docs.
As I also needed to make multiple PDF documents merge, I ended up doing the following. Many thanks to Adam Cameron for providing the solution to my initial issue.
In the template file, I use the <cfdocument> tag with the name attribute to save the PDF in a variable (thanks to Adam Cameron for this)
Then, I store all the PDF documents in an array in their binary format
In my view, I merge the PDF documents together by using <cfpdf>'s merge action, and using a cfloop, to loop over the array, inside it.
Finally, I display the content by using <cfcontent> and using the variable attribute with toBinary(myPdf)
This got me to where I am.
cfinclude will process the test.cfm page, and the way you configured cfdocument will cause "opening" of pdf document in your browser.
You can prevent openning of this file by saving file on the disc:
<cfdocument format="PDF" pagetype="A4" orientation="portrait" unit="cm" filename ="test.pdf" overwrite ="yes">
But this will not prevent execution of cfinclude in the cfcontent tag, it will just prevent opening in the browser.
You can observe cfinclude as request to the server, it will always be executed.
The solution would be to invoke request on test.cfm file which contains cfdocument in the moment that you actually want to generate pdf.
Example: Use javascript on client to invoke report service which will generate and pop out the screen with pdf report.
Hope this helps.

what is the actual meaning of parsing a html file?

I am not able to understand what actually parsing the html means ?
As i understand -
- it means that suppose we have any html file by parsing we can have the contents of the html file and we can edit them using parsing. Am i right ?? (parsing simply gives the idea about the contents and structure inside the file.)
I have one more question-
- I also want to know that suppose i have html file contents stored in a stream suppose (inside IStream *HTMLContents - No matter for now that how i got these contents). Is there any process exist that using these file contents may i create the preview on any window/Dialog Box/Preview pane with the same way exactly as i get the view of that html file in the browser.(for now you can imagine that i have downloded the HTML File contents from any web page(or from any where-No matter- But i have contents of html file in my stream i am sure about it) and i want to render that html file view in my own created window/Dialog Box/Preview pane(i mean it should view exactly as it appears in browser-Yes i know it won't be avle to display some pictures in html file but thats not a problem for me). How to do that ?? (I am using Visual c++ for my accomplishing my task)
Parsing basically means analyzing any data. When you parse HTML, it could be that you are figuring out where all the various elements are located and what do they do.
As for displaying HTML, it depends on what do you want to do:
If you want to open the file in your browser, use something like this.
As for displaying HTML directly in your form, I don't really know of any other way than parsing the HTML and creating your own web rendering engine. Good luck and have fun with that I guess.
Parse HTML means build object model such as DOM: https://en.wikipedia.org/wiki/Document_Object_Model in your program

cfimage from binary in cfdocument

I am writing a PDF dynamically, and am creating a QR code on the document for eTicketing purposes
i set my cfdocument localurl=yes to include a different image, which works fine, but since I am using an API call to get the binary for the qrCode, the using cfimage to display the image, it is only showing a red X
<cfdocument format="PDF" overwrite="Yes" localUrl="yes" pageType = "letter">
<body>
<cfoutput>
<section id="header">
<img src="file:///#ExpandPath('images/header.png')#"/>
<cfimage action="writeToBrowser" source="#rc.qrCode#" />
</cfoutput>
</body>
</html>
</cfdocument>
the source variable rc.qrCode is a binary response that works perfectly until i place inside cfdocument, it generates a url like this http://mysite/CFFileServlet/_cf_image/_cfimg-7945382145198648283.PNG as image source
i am sure this has todo with localurl and file:///, i just an not knowledgable enough to know why
Do not need to use physical path rather use relative path to your page.
e.g.
If you code in index.cfm of root folder and image inside images folder
try <img src="images/header.png"> , Note that it should not start with root path rather relative to your file.
UPDATE
writetoBrowser internally write file to hard drive to it's temporary location (topically, C:\ColdFusion10\cfusion\tmpCache\CFFileServlet) and while rendering it to browser it use relative path like "/CFFileServlet/_cf_image/_cfimg1592404668342998556.PNG", you can say that ColdFusion internally map CFFileServlet directory with all coldfusion site but notice leading forward slash and this makes issue with localurl=true. Since localurl=true either need physical path or relative path to your document.
Good idea is instead of writetobrowser you can write same image to harddrive at your location and give physical path in img tag. I do not this there will any performance issue since ColdFusion internally doing same thing when you are using writetobrowser attribute :)

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