I have an application that produces an image using HTML5 canvas. When the user wants to save the results, it flattens all the canvas layers into a new canvas and sends the string to be processed by Coldfusion into a PNG file.
The problem I'm having is that sometimes I get a Coldfusion error:
"Verify your inputs. The Base64 data is not in proper format. Data should be in the format understood by the tag in HTML, which is "data:image/jpg;base64,[base64 data]"
This happens only maybe 3% of the time. When I try to reproduce it using the exact same selections, it works fine.
This is the code that I'm using
<cfset image = imageReadBase64("#form.image#")>
<cfset fileName = #RandString(40)# & '.png'>
<cfimage
source="#image#"
destination="C:\something\#fileName#"
action="write"
overwrite = "yes">
Thank you
Related
Using django-screamshot plug to generating PDF.
Below is the URL of plugin
https://github.com/makinacorpus/django-screamshot
I am rending an HTML with Django-ScreamShot (CasperJs Option) to generate PDF.
Imaging are not coming after generating PDF. It is showing ? at the center.
Is it problem to rendering is fast so we need to wait ?
I found an alternative.
If we convert all the image to base64 and display them with image tag "< img src=' data:image/png;base64, ...' / >" image are coming in PDF also.
But if we use direct URL of image it don't show up on PDF and comes with ? at the center.
****Note I think when Casper Take a screenshot it don't wait for image to get load. So better convert all the images to base64 and display them in PDF also.**
I'm using a <cfhtmltopdf> tag to pull in a .cfm file as a template and create a PDF. All works well when I use jpg for the image format. But if the image is a BMP - for some reason it won't work.
In the template file , I'm using a <cfdirectory> tag with no filter to pull in the images.
<cfdirectory directory="E:\xxx\images\#image_ID#\" name="myDir" type="file" sort="datelastmodified">
then I'm using a <cfloop> to display images from the directory...
<cfloop query="myDir">
<cfif right(myDirMain.name,4) is ".bmp" >
<img src="#request.root#images/#images_ID#/#myDir.name#" border="0" width="230px" style="margin-bottom:15px;" />
</cfif>
This works great for jpg, but when trying to use bmp images - it's no good.
Does anyone know if a reason why bmp images are an issue or does only work with jpg images?
There seems to be a bug in the system that stops PDF's using BMP images. A solution is to convert them using <cfimage> tag before creating the PDF - its workaround that works, even thou it uses a little bit more server resources.
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.
I'm trying to create a CFML to WDDX packet as part of a caching mechanism. I get a cfwddx error related to a Java image variable when I attempt to pass in a coldfusion image as part of input. I can get the same error creating a new CF image and then passing that in as input.
<cfwddx action="cfml2wddx" input="#aNewCFImage#" output="wddxConverted" />
Error Occurred While Processing Request
Error reading property for java.awt.color.ICC_ColorSpace.maxValue.
ColdFusion 8
You'll have to send it over as a binary file.
see: http://books.google.ca/books?id=sWjmIxqeBxMC&pg=PA730&lpg=PA730#v=onepage&q&f=false
I'd convert the image to base64. That can be safely stored in a string.
I've learned how to add a watermark to a pdf.
<cfpdf action="addwatermark" image="NoteToSelf.png"
pages="1"
position="0,0"
showOnPrint="no"
source="my.pdf"
destination="#myDir#\new.pdf"
overwrite="yes"
opacity="10">
The way I read it, the watermark has to be an image. But NoteToSelf.png needs to be text that I've read from a database.
Q: How can I add text as a watermark?
Q: If I am required to use an image for the watermark, then how do I use the ImageNew tag to create an image of text?
ColdFusion 8.0.1 onwards you can supply text directly to the cfpdf tag:
<cfpdf action="addwatermark" position="10,10" text="I am the watermakr" source="pdfContent" rotation="90" foreground="yes">
If you are not on on 8.0.1 then you would need to use imageNew and the image write text functions and pass that in.