Skip to main content
Known Participant
June 20, 2014
Question

Coldfusion 11 cfheader or cfcontent 'failed to load PDF document'

  • June 20, 2014
  • 9 replies
  • 14538 views

I have a website that worked fine with Coldfusion 10 and now I have updated to Coldfusion 11 and this code doesn't work:

<cfheader name="content-disposition" value="inline; filename=#vPublicFile#" />

<cfcontent type="application/pdf" file="#DownloadFolder##qryDownload.fileNameOnserver#" deleteFile="no" />

If I type in the URL directly to the PDF file it loads fine, but if I try to get it through this code then I get the message "failed to load PDF document".  Even if I change the code to allow me to save the file, I get a saved file but it won't open in acrobat.

I know the code is working code, I tried it with Coldfusion 10 again just to make sure.  Something about 11 is stopping it from working.  Any ideas?

This topic has been closed for replies.

9 replies

Homestar9
Inspiring
November 18, 2016

I recently ran into this same issue on ColdFusion 2016 (update 3) on Windows 10 and also on Windows Server 2012.

I can confirm based on what previous posters have said that when IIS rewrite is enabled the wrong HTTP response headers are sent to the browser.  Additionally, the wrong content length is also sent.  I believe that this is a connector issue and not IIS.

Here is an example of the proper response header when accessing a file (e.g. /test/file.cfm?filesID=1)

Cache-Control:no-cache, no-store, must-revalidate, max-age=0

Content-Disposition:attachment; filename="Wag_Cameras_Administration_Documentation_10.pdf"

Content-Length:207349

Content-Type:application/unknown;charset=UTF-8

Date:Fri, 18 Nov 2016 01:16:02 GMT

Expires:Thu, 01 Jan 1970 00:00:00 GMT

Pragma:no-cache

Server:Microsoft-IIS/10.0

X-Powered-By:ASP.NET

Here's an example of the invalid response header when accessing a file via IIS rewrite (e.g. /test/file/1/)

Cache-Control:no-cache, no-store, must-revalidate, max-age=0

Connection:close

Content-Disposition:attachment; filename="Wag_Cameras_Administration_Documentation_10.pdf"

Content-Length:1284

Content-Type:application/unknown;charset=UTF-8

Date:Fri, 18 Nov 2016 01:16:39 GMT

Expires:Thu, 01 Jan 1970 00:00:00 GMT

Pragma:no-cache

Server:Microsoft-IIS/10.0

X-Powered-By:ASP.NET

There are two things wrong with the response header. The first is that "Connection: close" has been added as well as an incorrect content-length which is why the file you wind up downloading is a corrupted (incomplete) version of the PDF you wanted.

I created a bug in the adobe bugbase here: Bug#4197947 - <cfcontent> fails to serve PDF files when using IIS rewrite

Please vote for it.  Unfortunately since this issue is difficult to replicate if anyone can add their own replication code to the bug I'm sure it would be a big help to the dev team.

Participant
March 2, 2016

Still having this issue on ColdFusion 11 update 7 with latest connector installed when using iis rewrites with query string parameters.  Anyone else still having the problem?  Know of a quick fix other than writing a workaround?  IIS connector settings?  Thanks!

Participant
December 7, 2015

Is anyone still experiencing this issue or have a good fix for it?

Currently on Coldfusion 11 Update 7 and IIS 8 and experiencing the exact behavior as noted above. Having to implement a workaround for this would cost us quite a bit of development time.

Thank you!

Perkley1Author
Known Participant
February 3, 2016

Sorry didn't seem to get notified of this message and just saw it.  I am using Coldfusion 11 Update 7 and I still see the problem.

Participant
July 7, 2015

Is this still a thing?  I'm experiencing this on CF11 presently.

I can't make

<cfcontent file ="#literalFilePath#" type ="image/jpeg" />

work through a redirect, though it works fine when loaded without it.

I'm working with images on this task.  Will upgrading to the latest isapi_redirect.dll do the trick?

Thanks for your feedback!

Inspiring
November 18, 2014

We are also facing problems after updating to CF10 Update 14 with this issue. We do notice that the behavior is different based on the browser used on the client side. Photo uploads no longer work in Mango Blog 1.7 when using IE, but do work when using Google Chrome.

Participant
November 19, 2014
Participant
November 19, 2014

And provide any details so that they can "VERIFY" it.

Participant
November 13, 2014

Have you tried different versions of the browser? I am finding a similar issue with ColdFusion 11 running in  IE8..It works fine in FireFox and in IE10...

Participant
October 27, 2014

I'm seeing this issue after applying CF10 update 14 as well. We're on IIS 7.5.7600.16385 but do not have the IIS rewrite module installed. The specific issue we're seeing is that this URL will work:

/apps/news/picture/index.cfm?id=123

but this one will only return 4 bytes of data:

/apps/news/picture/?id=123

The script on this page is reading binary data from a database BLOB, then returning the content via:

<cfcontent type="image/jpeg" variable="#imagedata#">

Participant
October 30, 2014

I am having a simulair issue with cfcontent.

In my CF9 with IIS7 it is still working, with my new server with CF11 and IIS8 it is not working.

I use the same web.config in both old and new server (and also the same CF code)

The Rewrite URL is set like:

http://hostname/directory/image.png -> http://hostname/directory/index.cfm?image=image.png

In the index.cfm i do the following:

<cfheader name="Expires" value="#GetHttpTimeString(DateAdd('d', 100, Now()))#">

<cfcontent type="image/png" file="#customPath##attributes.image#"  />

While on the old server this shows the image, on the new server it is failing (nothing is shown).

When i just do a <cfdump var="test"/> in the index.cfm, it shows the text. (So it runs through the index.cfm).

But when i change it to cfcontent it fails.

Workaround it so turn off URL Rewriting and call the original URL:

http://hostname/directory/index.cfm?image=image.png

Perkley1Author
Known Participant
June 23, 2014

This is my solution right now:

My link was something like this: www.website.com/download/?file=encrypted, which fails.

If my link is like this: www.website.com/download/index.cfm?file=encrypted, then it succeeds.

Because I don't want to show index.cfm, I used ISAPI ReWrite and now have this URL: www.website.com/download/encrypted, which in turn processes it as index.cfm?file=encrypted, and that works fine.

However, I have some other areas where I do the same type of thing to generate a PDF and having the same issue.

Is someone else willing to try a similiar link: www.website.com/download/?anyparam=anything and see if they get the same problem.  To me this seems like a bug.

Eduardo Athar
Participating Frequently
June 24, 2014

Hi!
Your problem is with IIS and not with Coldfusion. The way you wrote your url rewrite not include the call but you can make it a rule to rewrite these parameters for you. I had such a problem with the cf chart and had to create a rule for him and even mapping of the CFIDE directory as a virtual directory to function internally.

Perkley1Author
Known Participant
June 24, 2014

I am not exactly sure I follow what you are saying.  In CF10 it worked fine, in CF11 it doesn't.  I know it still runs index.cfm because if I give it a bad filename it crashes and shows me that it can't find the file, and when I do have the filename correct it does give me a file, it is just corrupt.  So whether I include index.cfm or not in the url they both run the file, one just delivers the file fine and the other one doesn't.

cfchart works fine for me.  Again, maybe I just don't exactly understand the area you are referring to.

BKBK
Community Expert
Community Expert
June 21, 2014

Are the paths exactly what you expect? Check

<cfoutput>

#vPublicFile# <br>

#DownloadFolder##qryDownload.fileNameOnserver#

</cfoutput>

<!---

<cfheader name="content-disposition" value="inline;filename=#vPublicFile#" />

<cfcontent type="application/pdf" file="#DownloadFolder##qryDownload.fileNameOnserver#" deleteFile="no" />

--->

Perkley1Author
Known Participant
June 21, 2014

Yes, the paths are correct.  I did check that before posting. Like I said,  it works in CF10.  It shouldn't work in CF10 if the files were not found.  As far as I understand the filename in cfheader can be whatever I want, right?  That is just how the user receives it.

BKBK
Community Expert
Community Expert
June 21, 2014

Perkley wrote:

Like I said,  it works in CF10.  It shouldn't work in CF10 if the files were not found.

The reasoning behind my suggestion is that there usually are subtle changes that may occur when you change versions. For example, there just might be a character in the path, that is compatible with Coldfusion 10's settings but not with Coldfusion 11's. This is more a process of elimination than anything else.

You could do two more tests to rule out the obvious. Firstly, the 'inline' attribute implies the PDF is to be opened by the browser. So, to rule out browser quirks, open the CFM page in different browsers. Any change?

Secondly, test by swtching from 'inline' to 'attachment'. Any improvement?

As far as I understand the filename in cfheader can be whatever I want, right?

Yes, any filename, whatever_you_want.pdf, will do.