PDF files download through content/download not working

Author Message

V. van Velzen

Wednesday 01 December 2010 6:02:07 am

Goodday,

Since the upgrade to 4.4 the links to downloadable PDF files (of the form /content/download/3570/39933/version/1/file/XYZ.pdf) on my site are no longer working. When trying to open the file I get the following message:

"Acrobat could not open XYZ.pdf because it is either not a supported file type or because the file has been damaged"

When I open the file directly from the /storage/original/application/ folder, the PDF opens without a problem.

I've compared the saved PDF file gotten with the /content/download link to the original file (opened both in Notepad++) and the saved PDF file seems to be missing several lines on the bottom of the file, i.e. it doesn't end with %%EOF. I think this could be the problem, but I've got no idea where to look in the code of EZPublish to fix this. Any help would be appreciated.

TIA,

Vivienne

André R.

Wednesday 01 December 2010 6:25:03 am

Take a look in kernel/content/download.php, might be that the content range support added in 4.4 is causing issues.

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

V. van Velzen

Wednesday 01 December 2010 6:35:54 am

Hi Andre,

Thanks for your response. I've looked in kernel/content/download.php, but can't find anything about a content range. Could you please point me in the right direction?

V. van Velzen

Tuesday 07 December 2010 2:10:51 am

Some further information: it doesn't matter if the PDF file is large or small, the last portion of the file is seemingly cut off. Javascript has been added to the beginning of the file (setting cookies), don't know if this is the problem. So, no solution found yet, any help would be greatly appreciated as visitors are now unable to view PDF files posted to the website.

TIA,

Vivienne

Gaetano Giunta

Tuesday 07 December 2010 3:29:48 am

"

Javascript has been added to the beginning of the file (setting cookies)

"

Care to explain how this is done?

Principal Consultant International Business
Member of the Community Project Board

V. van Velzen

Tuesday 07 December 2010 3:44:43 am

I have no idea. I think it's something that EZPublish does, as it only shows up when I'm looking at a file downloaded through the EZPublish interface. Below is the Javascript code that has been added:

<Script language='JavaScript'>
<!--

function Get_Cookie(name) { 
   var start = document.cookie.indexOf(name+"="); 
   var len = start+name.length+1; 
   if ((!start) && (name != document.cookie.substring(0,name.length))) return null; 
   if (start == -1) return null; 
   var end = document.cookie.indexOf(";",len); 
   if (end == -1) end = document.cookie.length; 
   return unescape(document.cookie.substring(len,end)); 
} 

function Set_Cookie(name,value,expires,path,domain,secure) { 
    var cookieString = name + "=" +escape(value) + 
       ( (expires) ? ";expires=" + expires.toGMTString() : "") + 
       ( (path) ? ";path=" + path : "") + 
       ( (domain) ? ";domain=" + domain : "") + 
       ( (secure) ? ";secure" : ""); 
    document.cookie = cookieString; 
} 

function Delete_Cookie(name,path,domain) { 
   if (Get_Cookie(name)) document.cookie = name + "=" + 
      ( (path) ? ";path=" + path : "") + 
      ( (domain) ? ";domain=" + domain : "") + 
      ";expires=Thu, 01-Jan-70 00:00:01 GMT"; 
} 

var today = new Date(); 
var zero_date = new Date(0,0,0); 
today.setTime(today.getTime() - zero_date.getTime()); 
var cookie_expire_date = new Date(today.getTime() + (8 * 7 * 86400000)); 

function setVisitorID() { 
   if (Get_Cookie('VisitorID')) { 
       var VisitorID = Get_Cookie('VisitorID'); 
   }else{ 
       Set_Cookie('VisitorID',Math.random(),cookie_expire_date); 
   } 
} 

function setSessionID() { 
   if (!Get_Cookie('SessionID')) 
       Set_Cookie('SessionID',Math.random()); 
} 

var loaded_script = true; 

-->
</Script>

<script language="jscript">
  setVisitorID();
</script>

Gaetano Giunta

Tuesday 07 December 2010 5:58:29 am

That javascript is not part of any standard eZ distribution I know of. It might be added by some custom development done on your site, or even by your ISP - some free ones do add this kind of crap on top the pages generated.

Now, if the js nests itselft at the bottom of the file it will probably not be a problem, but if it goes on top of it, and the http Content-Length header is not updated accordingly, it might explain why the bowser gets a truncated file.

So: investigate more on the origin of the js in question.

Principal Consultant International Business
Member of the Community Project Board

V. van Velzen

Tuesday 14 December 2010 2:32:03 am

Thanks Gaetano, I've taken it up with the hosting provider and they indeed placed the JavaScript at the start of every requested page/file. Once they removed it, the downloading of PDF files once again worked as it should.

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 18 2025 00:45:41
Script start
Timing: Jan 18 2025 00:45:41
Module start 'layout'
Timing: Jan 18 2025 00:45:41
Module start 'content'
Timing: Jan 18 2025 00:45:42
Module end 'content'
Timing: Jan 18 2025 00:45:42
Script end

Main resources:

Total runtime0.9872 sec
Peak memory usage4,096.0000 KB
Database Queries74

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0052 589.3125152.6563
Module start 'layout' 0.00520.0033 741.968839.5000
Module start 'content' 0.00850.9774 781.4688640.4766
Module end 'content' 0.98590.0013 1,421.945320.1094
Script end 0.9872  1,442.0547 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00360.3623160.0002
Check MTime0.00140.1452160.0001
Mysql Total
Database connection0.00070.072610.0007
Mysqli_queries0.919593.1381740.0124
Looping result0.00080.0843720.0000
Template Total0.955296.820.4776
Template load0.00240.240220.0012
Template processing0.952896.513920.4764
Template load and register function0.00010.014410.0001
states
state_id_array0.00180.180410.0018
state_identifier_array0.00090.087320.0004
Override
Cache load0.00210.2119370.0001
Sytem overhead
Fetch class attribute can translate value0.00090.087630.0003
Fetch class attribute name0.00120.1207100.0001
XML
Image XML parsing0.00110.112430.0004
class_abstraction
Instantiating content class attribute0.00000.0033110.0000
General
dbfile0.00110.1121230.0000
String conversion0.00000.001040.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
8content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
11content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
2content/datatype/view/ezxmltags/emphasize.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/emphasize.tplEdit templateOverride template
3content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
1content/datatype/view/ezxmltags/quote.tpldatatype/ezxmltext/quote.tplextension/ezwebin/design/ezwebin/override/templates/datatype/ezxmltext/quote.tplEdit templateOverride template
1content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 28
 Number of unique templates used: 8

Time used to render debug report: 0.0001 secs