Cfdocument and image not displaying in pdf [solved]

I search around and found other people with the same issue, but no solutions.

I am making a pdf and I want to embed an image. I have 2 lucee Apps, same server, same code, different directories, In the 1st dir with no issue, pdf looked great. When I moved the code(below) to the second directory, the pdf always is created with the image not drawn. The image file is present in both directory hierarchies.

Any help in getting this to work or at least an output any error that can be causing this? All i have is a pdf with the image border with nothing inside.

<<cfscript>

function evidence(app_id,brand,rowcount,fname,data){

if (FileExists(fname)) FileDelete(fname);

cfdocument(
    format            = "pdf"
    filename          = fname
    backgroundvisible = "yes"
    fontembed         = "yes"
    marginbottom      = "100"
    marginleft        = "100"
    marginright       = "100"
    margintop         = "100"
    pageheight        = "100"
    pagewidth         = "100"
    localURL = "true"
) {
    cfdocumentitem( type = "header" ) {
           //header
    }

    cfdocumentsection() {

       writeoutput(' <img src="images/recert_report_pict1.png" height="480" width="600" alt="image" style="border:5px solid black">');
    }

    cfdocumentitem( type = "footer" ) {
        //footer section
    }
  }
}

fname_output = getTempDirectory() & 'marc.pdf';
evidence(1,'GFI',2,fname_output,1);

cfheader( name="Content-Disposition" value='attachment; filename="marc.pdf"' );
cfcontent( type="application/x-zip-compressed" file="#fname_output#" deletefile="true" );
</cfscript>




As a test of the image is found, i created this simple test and it works to the browser.


<<cfscript>
     writeoutput(' <img src="images/recert_report_pict1.png" height="480" width="600" alt="image" style="border:5px solid black">');

</cfscript>

@marcw, Always mention the version

@marcw, Mention PDF extension version too for both(worked,non-worked) apps

How do i get the pdf version? Do you mean my pdf file? If not, please show me

I added the attachement

marc (40).pdf (877 Bytes)

Get that from Applications–>installed->PDF–>installed version.

@marcw, Please add that affected PDF too.

i go the the admin page and I click on the pdf, but nothing happens. The pdf Extension icon changes as I hover but does not show the version. Is there another way to grab it? Logs?
image

PDF I created
marc (40).pdf (877 Bytes)

here are the jar files with pdf in the name

the PDF extension is usually installed under the server admin (red) you’re looking at the web admin (blue)

Cool. Currently, you are in Admin web. But, you should see the extension in Admin Server → Applications.
Please go through lucee/admin/server.cfm?action=ext.applications.

Thanks, fyi, the working and non working apps are on the same server. The only difference is the directory. Everything else is the same.

So i have 2 dirs(change for simplicity)
/appl/lucee/reports/marc1
/appl/lucee/reports/marc2

So my real.cfm program in marc1 works with no issues. I moved the real.cfm code to marc2 directory and that did not work. So I made the test.cfm in marc2 and that did not work. I just tested test.cfm in marc1 and the pdf does not work. Strange, the image tag is the same. If needed i will upload the real.cfm, but it has a lot of other code(noise) vs the test.cfm

@marcw, Could you please check the image exists in your directory and the src path is correct.

I added FileExists to the pdf test.cfm files. FileExistsis is true in both directories but the image tag does not work in the second dir.

Question about the image tag. I tried to change src to relative and absolute and many other ways. What is the correct way to code the “src” path for a pdf. Not the issue here, but might help. I coded it as a html.

This is dir1 :

This is dir 2:

<<cfscript>

function evidence(app_id,brand,rowcount,fname,data){

if (FileExists(fname)) FileDelete(fname);

cfdocument(
    format            = "pdf"
    filename          = fname
    backgroundvisible = "yes"
    fontembed         = "yes"
    marginbottom      = "100"
    marginleft        = "100"
    marginright       = "100"
    margintop         = "100"
    pageheight        = "100"
    pagewidth         = "100"
    localURL = "true"
) {
    cfdocumentitem( type = "header" ) {
           //header
    }

    theDir=GetDirectoryFromPath(GetCurrentTemplatePath());
    imgname = theDir & "images/recert_report_pict1.png";
    cfdocumentsection() {
      if (FileExists(imgname)){
         writeoutput('***exist*** #imgname#');
      }
      else{
         writeoutput('Does not exist #imgname#');
      }

      writeoutput(' <img src="images/recert_report_pict1.png" height="480" width="600" alt="image" style="border:5px solid black">');
    }

    cfdocumentitem( type = "footer" ) {
        //footer section
    }
  }
}

fname_output = getTempDirectory() & 'marc.pdf';
evidence(1,'GFI',2,fname_output,1);

cfheader( name="Content-Disposition" value='attachment; filename="marc.pdf"' );
cfcontent( type="application/x-zip-compressed" file="#fname_output#" deletefile="true" );
</cfscript>


are you seeing any 404s in your web server logs?

Nope,it just works fine with image. But without the image it shows the border only and doesn’t throw any error.

Confused, how can the image tag be bypassed? The 1st line is dir2, 2nd and 3rd line is dir1,

the web-server does not register the image tag in dir2.

the 2nd 3rd line, the image and test.cfm are registerd.

Why would the entire img tag not show?

do the 404s get logged to the access.log or error.log ?

if imageWriteToBrowser() allowed passing thru custom attributes for the image tag, it would be a nice solution, but it currently just sets the height and width to the image size and you can’t pass in a css class or style. That would completely avoid the whole problem of paths

this added the height and width [LDEV-2330] - Lucee

404 goes to the same access.log

found the fix, need to use “file:///” in the beginning of source. Not sure why is worked in one place and not the other.

theDir=GetDirectoryFromPath(GetCurrentTemplatePath());
imgname = theDir & "images/recert_report_pict1.png";

 writeoutput('<img src="file:///#imgname#" height="480" width="600">');