Skip to main content
Known Participant
January 25, 2023
Answered

Cold fusion 2021 sometimes image breaks while creating pdf file

  • January 25, 2023
  • 1 reply
  • 826 views

Recently we moved from cfusion11 to 2021. While generating pdf file sometimes image breaks. Please suggest us solution if anybody face same issue and came out from that.

    This topic has been closed for replies.
    Correct answer Faizan278243197lsr

    I think the following description is a clue: "Image we are retrieving through the database which contains in BLOB form".

    The process of retrieving the image may be too slow, or even interrupted. Possible reasons for this include slow or interrupted movement of image bytes down the wire or a slow or interrupted database connection.

     

    Suggestion: cache the query that retrieves the blob. You could, for example, cache the query for 1 day as follows:

    <!--- Using cachedWithin attribute to cache query for 1 day --->
    <cfquery cachedWithin="#createTimeSpan(1,0,0,0)#" name="xxx" datasource="yourDSN">
    ...
    </cfquery>

     


    Now retrieving image from DB and saving into temp folder at server and after that the image fetching into PDF. So this is working fine now.

    1 reply

    Charlie Arehart
    Community Expert
    Community Expert
    January 25, 2023

    You haven't clarified how you're creating the PDF. Are you using CFDOCUMENT or CFHTMLTOPDF (introduced in CF11)? Since you don't clarify, I'll assume it's the older cfdocument.

     

    And as a first quick possible solution (knowing nothing more), try adding localurl="true" to the cfdocument tag. Does that work? If it does, we can explain why later. If it does not, take it out. 

     

    When you say it "sometimes breaks", do you mean the same image (in the same PDF generated with the same CFML page) sometimes breaks and sometimes works? If it's the same image, that would be odd (but let us know, either way). 

     

    Next, what's the URL of an image that is always "breaking"? Is it specified as a full or relative URL in the img src tag within the cfdocument (or cfhtmltopdf)? If it's relative, does it "work" if you make it full (domain and path as well as file name)?

     

    Finally, if you created a test page that did a cfhttp of the full url (holding the image), does that work? Does a dump of the cfhttp scope after it show that it has binary image file data?

     

    I know you want the "solution", but until we know for sure what your problem is, we have to guess at things and suggest such diagnostics to get us closer to it. Or maybe someone else will offer "the solution" without any further clarification from you.

    /Charlie (troubleshooter, carehart. org)
    Inspiring
    January 26, 2023

    Thanks, Charlie for your prompt response. 

    I will reply to you point-wise as you asked the question:

    1. I am using CFDOCUMENT and as per your recommendation I have added localurl="true" now I will monitor the same issue will not repeat again.

    2. Yes, the image and generated barcode break sometimes only. The same image and barcode will visualize correctly if I will generate it a few minutes later.

    3. Image we are retrieving through the database which contains in BLOB form with JPEG extension.

    Used tag under CFDOCUMENT

    <p style="position: absolute; top:30px; right: 43px; width: 0px; padding: 0px;">
    <cfimage action="writetobrowser" isBase64="true" source="#local.getpassportinfo.IMAGE#" width="75px" height = "87px">
    </p>
    <p style="position: absolute; top:29px; right: 3px; width: 0px; padding: 0px;">
    <cfimage action="writetobrowser" isBase64="true" source="#barcode#" height = "120px" width="35px" >
    </p>

    I did not understand your last questions:

    Next, what's the URL of an image that is always "breaking"? Is it specified as a full or relative URL in the img src tag within the cfdocument (or cfhtmltopdf)? If it's relative, does it "work" if you make it full (domain and path as well as file name)?

     

    Finally, if you created a test page that did a cfhttp of the full url (holding the image), does that work? Does a dump of the cfhttp scope after it show that it has binary image file data?

    If the above-given answers are enough for you to provide the solution it will be better otherwise we can discuss it further.

    Charlie Arehart
    Community Expert
    Community Expert
    January 26, 2023

    I don't understand why you would be using cfimage within the cfdocument. Why not simply use the html "img src" tag? Have you tried that?

     

    Or is this just code you have inherited, and perhaps you don't have experience with either cfml or html? If that's the case, do clarify, as it could change the level of detail that I or others could offer.

     

    Finally, as for my last questions, I'll simplify things (now that you say the image url comes from a db lookup) : what exactly is the value of the url for the image (in that local.getpassportinfo.IMAGE variable) when it fails to work? 

    /Charlie (troubleshooter, carehart. org)