New to Lucee and ran into an odd issue. I am using CFIMAGE with the WriteToBrowser action.
<cfimage source="d:\somepath\someimage.png" name="myImage" action="writetobrowser" height="52" />
Verified the file is there, but no output to the browser, nor does it throw an error. Am I missing something?
Thanks in advance.
Alberto
Hi @alberto ,
From your code just remove the name attribute then you’ll see your image on the browser.
As per docs, Name attribute is required for action=“read”. If you dump the name attribute from your code you can see the details of your image that will hold by the name.
Is this an incompatibility with ACF?
Silently failing isn’t great…
Hi @cfmitrah ,
Thanks that worked! Unfortunately, the height parameter in the tag is not being respected. This is the output.
<img src="/lucee/graph.cfm?img=163C25D7-D89B-4932-8B92EBDB9BC21C93.png&type=png" width="512" height="354">
In any case, I will keep playing with it.
Alberto
Quick update… I tried adding the width parameter as well but that did not help. I also tried the passthrough parameter, which did work. Then, I decided it was better to not resize inline. Instead, I just wrote a script to resize the images en masse. This way I take the need of the inline resize out of play, which leans out the request from a disk IO and processor perspective.
Thanks again!
marcB
November 28, 2019, 6:41am
9
Hello,
My configuration :
Windows Server 2016 (10.0) 64bit
Lucee 5.3.3.62
Apache Tomcat/9.0.24
95/5000
It works when displayed in the browser but not in a pdf generated by cddocument …
any Idea ?
Regards,
Marc
<cfoutput>
<cfscript>
code128= createobject("java","com.lowagie.text.pdf.Barcode128");
code128.setCodeType(code128.CODE128);
/* Set the code to generate */
code128.setCode("1000027175");
color = createobject("java","java.awt.Color");
image = code128.createAwtImage(color.black, color.white);
bufferedImage = createObject("java", "java.awt.image.BufferedImage");
bufferedImageType = bufferedImage.TYPE_BYTE_GRAY;
bufferedImage = bufferedImage.init(image.getWidth(JavaCast("null", "")),image.getHeight(JavaCast("null", "")), bufferedImageType);
graphics2D = bufferedImage.createGraphics();
graphics2D.drawImage(image,0,0,JavaCast("null", ""));
barcodeImage = imageNew(bufferedImage);
</cfscript>
<cfimage action="writeToBrowser" source="#barcodeImage#" format="png" quality="1" width="180px" overwrite = "yes">
</cfoutput>
@marcB , Could you please share your extension version here.
marcB
November 28, 2019, 7:18am
11
@cfmitrah what you mean with “extension” ?
Thanks
@marcB , What is your PDF Extension version?
marcB
November 28, 2019, 7:24am
13
@cfmitrah ok, sorry
Installed version 1.0.0.75
@marcB , I’ve checked this with as your PDF extension version also. It works fine for me in my local. Could you please test according to the example?
<cfoutput>
<cfscript>
code128= createobject("java","com.lowagie.text.pdf.Barcode128");
code128.setCodeType(code128.CODE128);
code128.setCode("1000027175");
color = createobject("java","java.awt.Color");
image = code128.createAwtImage(color.black, color.white);
bufferedImage = createObject("java", "java.awt.image.BufferedImage");
bufferedImageType = bufferedImage.TYPE_BYTE_GRAY;
bufferedImage = bufferedImage.init(image.getWidth(JavaCast("null", "")),image.getHeight(JavaCast("null", "")), bufferedImageType);
graphics2D = bufferedImage.createGraphics();
graphics2D.drawImage(image,0,0,JavaCast("null", ""));
barcodeImage = imageNew(bufferedImage);
</cfscript>
<cfimage action="writeToBrowser" source="#barcodeImage#" format="png" quality="1" width="180px" overwrite = "yes">
<cfdocument format="pdf">
<cfimage action="writeToBrowser" source="#barcodeImage#" format="png" quality="1" width="180px" overwrite = "yes">
</cfdocument>
</cfoutput>
marcB
November 28, 2019, 10:45am
15
@cfmitrah we have https:// server and http:// server, on SSL server nothing appears on the PDF, for the unsecure server i got the same result as you.
andreas
November 29, 2019, 10:30pm
16
The value of “barcodeImage” is a complete genertated HTML-Tag with inline base64-data, like so:
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFoAAAAYCAAAAABfU7W5AAAAOUlEQVR42u3MQQ4AIAgDwf3/p2u0Bm++YA+SAjJASOCU7Nw+M3lvaif92dsubmpEWlpaWlpaWvpHL4yrS+0oV1IdAAAAAElFTkSuQmCC">
thus you can simply add it without any use of cfimage
This should do the trick:
<cfoutput>
<cfscript>
code128= createobject("java","com.lowagie.text.pdf.Barcode128");
code128.setCodeType(code128.CODE128);
code128.setCode("1000027175");
color = createobject("java","java.awt.Color");
image = code128.createAwtImage(color.black, color.white);
bufferedImage = createObject("java", "java.awt.image.BufferedImage");
bufferedImageType = bufferedImage.TYPE_BYTE_GRAY;
bufferedImage = bufferedImage.init(image.getWidth(JavaCast("null", "")),image.getHeight(JavaCast("null", "")), bufferedImageType);
graphics2D = bufferedImage.createGraphics();
graphics2D.drawImage(image,0,0,JavaCast("null", ""));
barcodeImage = imageNew(bufferedImage);
</cfscript>
<cfdocument format="pdf">
#barcodeImage#
</cfdocument>
</cfoutput>
marcB
December 2, 2019, 6:06am
17
andreas:
code128= createobject(“java”,“com.lowagie.text.pdf.Barcode128”); code128.setCodeType(code128.CODE128); code128.setCode(“1000027175”); color = createobject(“java”,“java.awt.Color”); image = code128.createAwtImage(color.black, color.white); bufferedImage = createObject(“java”, “java.awt.image.BufferedImage”); bufferedImageType = bufferedImage.TYPE_BYTE_GRAY; bufferedImage = bufferedImage.init(image.getWidth(JavaCast(“null”, “”)),image.getHeight(JavaCast(“null”, “”)), bufferedImageType); graphics2D = bufferedImage.createGraphics(); graphics2D.drawImage(image,0,0,JavaCast(“null”, “”)); barcodeImage = imageNew(bufferedImage); #barcodeImage #
@andreas
Won’t work …
(work in the browser not in the document tag)
Message is :
Failed to load the PDF document
When i look at the console :
Uncaught TypeError: Cannot read property 'appendChild' of null
at generateInstalledElement (content.js:18)
and :
Uncaught TypeError: Cannot read property 'innerHTML' of null at contentscript.js:1
andreas
December 2, 2019, 8:39am
18
@marcB :
that is really strange. That code works on my environment perfectly. I’ve even installed TLS 1.2 on Tomcat to check it and that code 've submitted works. This is my environment:
PDF-Extension: Installed version 1.0.0.75
Version Lucee 5.3.3.62-SNAPSHOT
Servlet Container Apache Tomcat/9.0.11
Java 1.8.0_202 (Azul Systems, Inc.) 64bit
Host Name localhost
OS Windows 10 (10.0) 64bit
What happens if you just dump the generated code without any cfdocument to see the generated content? What is your output?
<cfdump var="#barcodeImage#">
and what happens when you hardcode the generated HTML into the cfdocument:
<cfdocument format="pdf">
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFoAAAAYCAAAAABfU7W5AAAAOUlEQVR42u3MQQ4AIAgDwf3/p2u0Bm++YA+SAjJASOCU7Nw+M3lvaif92dsubmpEWlpaWlpaWvpHL4yrS+0oV1IdAAAAAElFTkSuQmCC">
</cfdocument>
?
andreas
December 2, 2019, 8:53am
19
marcB:
Message is :
Failed to load the PDF document
When i look at the console :
Uncaught TypeError: Cannot read property 'appendChild' of null
at generateInstalledElement (content.js:18)
and :
Uncaught TypeError: Cannot read property 'innerHTML' of null at contentscript.js:1
Do you mean your Browser-Console? This seems to be a Browser Error and is not related to Lucee or cfdocument. Maybe you are trying to load the pdf document with javascript? If so, it can be anything. CORS (you meantioned something about SSL) I really can’t say, just guess. All I can say is that the code I’ve provided is working.
marcB
December 2, 2019, 9:00am
20
@andreas
Really strange …
this is working in the browser but isn’t working when inserted in cfdocument tag …
< cfimage action=“writeToBrowser” source=“#barcodeImage #” format=“png” quality=“1” width=“180px” overwrite = “yes” >
but both are working on a non secure server.
andreas
December 2, 2019, 9:11am
21
I think you have an Browser/Javascript Issue. See:
https://stackoverflow.com/questions/30014090/uncaught-typeerror-cannot-read-property-appendchild-of-null/30014117
Remember: When you are not using cfdocument, the page will be generated in HTML with content-type: text/plain. That content can be read by Javascript from another page. But if you use cfdocument there is no HTML being genertated, but a PDF file of content-type: application/pdf. Javascript won’t be able to grab any html the same way from that file, because it’s a PDF, not a HTML file.