Feng Forum

Support => How To's => : MicMac February 08, 2010, 06:56:42 AM

: PDF Viewing - MIME application/pdf
: MicMac February 08, 2010, 06:56:42 AM
Hi FO-Team,

we are still looking for a possibility  to show pdf-files directly in FO, i.e. like jpg.

Any idea to do that ?

thx

Mic


: Re: PDF Viewing - MIME application/pdf
: cabeza February 24, 2010, 12:40:35 PM
We can develop this is we find sponsors for the project.
Contact us at contact   @   fengoffice
: Re: PDF Viewing - MIME application/pdf
: altert August 13, 2011, 08:59:04 AM
It's possible to do it for at least google chrome - There was post on this in german forum:
Versionen: 1.5 - 1.7.3.1
Folgende Datei muß bearbeitet werden: /application/views/files/file_details_content.php
Nachfolgenden Code müßt ihr nach Zeile 31 (kann je nach Versionsstand von FO variieren) einfügen

Code:
<?php
   if (substr($file->getFilename(), -3) == 'pdf')
   {
       echo'<div>';
       $urlpdf=get_url('files', 'download_image', array('id' => $file->getId(), 'inline' => true, 'modtime' => $modtime));
       echo "<iframe src=".$urlpdf." width='100%' height='900px' frameborder=0 align='center'></iframe>";
       echo '</div>';
   }
?>
: Re: PDF Viewing - MIME application/pdf
: jolivaresd August 22, 2011, 04:02:37 PM
Friends,

I modified a code, you can see it in
http://forums.fengoffice.com/index.php?topic=14332.0

Regards,
Joaquin
: Re: PDF Viewing - MIME application/pdf
: franponce87 August 24, 2011, 04:10:54 PM
Great input Altert and Joaquín!
I have made slight changes with both of your codes to make one that covers links as well:

<?php
   if (substr($file->getFilename(), -3) == 'pdf'){
      echo'<div>';
      if($file->getType() != ProjectFiles::TYPE_WEBLINK){       
        $urlpdf=get_url('files', 'download_image', array('id' => $file->getId(), 'inline' => true, 'modtime' => $modtime));
      }else{      
        $urlpdf=$file->getUrl();
      }
      echo "<iframe src=".$urlpdf." width='100%' height='900px' frameborder=0 align='center'></iframe>";
      echo '</div>';
   }
?>

I already tried it and it does work for IE 7 onwards, FireFox, SeaMonkey, Goolge Chrome, Opera

Best regards,
Francisco
: Re: PDF Viewing - MIME application/pdf
: timveer October 14, 2011, 05:49:41 AM
Hey guys, sounds interesting, but unfortunately no Spanish in this boy's blood!

Can anyone help out a linguistically challenged user and post an English How-to...

Thanks,
Tim
: Re: PDF Viewing - MIME application/pdf
: potion October 15, 2011, 05:46:27 PM
@Tim - Spanish? Looks like German to me!

Here's the English:

File to edit:  /application/views/files/file_details_content.php

Insert after line 32 (Feng Office 1.7.5 - may vary depending upon version)
:
<?php    //Francisco's edited version
   
if (substr($file->getFilename(), -3) == 'pdf'){
      echo
'<div>';
      if(
$file->getType() != ProjectFiles::TYPE_WEBLINK){       
        
$urlpdf=get_url('files''download_image', array('id' => $file->getId(), 'inline' => true'modtime' => $modtime));
      }else{      
        
$urlpdf=$file->getUrl();
      }
      echo 
"<iframe src=".$urlpdf." width='100%' height='900px' frameborder=0 align='center'></iframe>";
      echo 
'</div>';
   }
?>

Denis
: Re: PDF Viewing - MIME application/pdf
: timveer October 22, 2011, 07:00:08 PM
Hey Denis,

Thanks for that.

Actually I was looking at Joaquin's response (two threads before) linking to:
forums.fengoffice.com/index.php?topic=14332.0

This looked more in depth. I'd like to know how to make the change, but understanding the mechanics of it, will help to understand it on a larger scope.

Cheers,
Tim
: Re: PDF Viewing - MIME application/pdf
: franponce87 November 03, 2011, 11:31:36 AM
Hey guys, sounds interesting, but unfortunately no Spanish in this boy's blood!

Can anyone help out a linguistically challenged user and post an English How-to...

Thanks,
Tim
You may actually use the code I have added to my post above and it will certainly work :)

That code should go in
fengoffice/application/views/files/file_details_content.php
About ln 32

Best regards,
Francisco
: Re: PDF Viewing - MIME application/pdf
: timveer November 03, 2011, 05:08:39 PM
Thanks Francisco  ;D
: Re: PDF Viewing - MIME application/pdf
: GGeczy November 21, 2011, 12:32:58 AM

The suggested solution to embed the PDF in a frame has the issue that it may not work if the client system has their browser set to not show PDF files in-browser.  So this may instead force a download of the PDF or cause other oddities.

However I took the above concept and tackled it from a different side, using the Google Viewer application to do the preview for me.  (Google allows the embedding of this, see  docs.google.com/viewer for information).

Using this, I can provide previews of not just PDF but also DOC, XLS, PPT, etc.

For those interested here is how it was implemented:

In /application/views/files/file_details_content.php :

 
:
<?php
 
   
if (substr($file->getFilename(), -3) == 'pdf' || substr($file->getFilename(), -3) == 'doc' || substr($file->getFilename(), -3) == 'xls' || substr($file->getFilename(), -3) == 'ppt' || substr($file->getFilename(), -4) == 'docx' || substr($file->getFilename(), -4) == 'pptx' || substr($file->getFilename(), -4) == 'xlsx'){
      echo
'<div>';
      if(
$file->getType() != ProjectFiles::TYPE_WEBLINK){       
// WAS:        $urlpdf=get_url('files', 'download_image', array('id' => $file->getId(), 'inline' => true, 'modtime' => $modtime));
// GG: Instead, need to use a sandbox URL, so that the non-logged in site (google) can access the document using a user token....
$urlpdfget_sandbox_url("feed""display_content", array("id" => $file->getId(), "user_id" => logged_user()->getId(), "token" => logged_user()->getTwistedToken()));
      }else{      
        
$urlpdf=$file->getUrl();
      }
      
// WAS: echo "<iframe src=".$urlpdf." width='100%' height='900px' frameborder=0 align='center'></iframe>";
      // GG: Try google embed:  (encode some of the url characters)
      
$urlpdf str_replace('&''%26'$urlpdf);
      
$urlpdf str_replace('?''%3F'$urlpdf);
      
$urlpdf str_replace('=''%3D'$urlpdf);
      
$urlpdf str_replace('/''%2F'$urlpdf);
      
$urlpdf str_replace(':''%3A'$urlpdf);
      echo 
"<iframe src=[blocked]docs.google.com/viewer?embedded=true&url=".$urlpdf." width='100%' height='900px' frameborder=0 align='center'></iframe>";
 
      echo 
'</div>';
   }
 
?>


I also needed to change
 /application/controllers/FileController.class.php :

Edited in function display_content(), to allow proper downloading of PDF etc files :
 
:
if ($file->getTypeString() == 'text/html') {
header("Expires: " . gmdate("D, d M Y H:i:s", mktime(date("H") + 2, date("i"), date("s"), date("m"), date("d"), date("Y"))) . " GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Content-Type: " . $file->getTypeString() . $charset);
header("Content-Length: " . (string) strlen($html_content));
 
print($html_content);
} else {
download_from_repository($file->getLastRevision()->getRepositoryId(), $file->getTypeString(), $file->getFilename(), !$inline);

}

The "print($html_content)" didn't support sending the PDF data, so if not text then it uses download_from_repository instead.

Note that this embed does use the "login via token" feature that seems to exist for the RSS feed support...  as such, it contains the same security issue that has been discussed on these forums for the token URLs - if you are not accessing your site via https then there could be over-the-wire leakage of a URL that would allow viewing content without login.
: Re: PDF Viewing - MIME application/pdf
: GGeczy November 21, 2011, 12:34:37 AM
Oh and where it says "[blocked]" in the iframe section replace it with "https" and a colon and two slashes, no quotation marks - it won't let me post anything that looks like a web link in my message.

: Re: PDF Viewing - MIME application/pdf
: PSchnittger November 22, 2011, 12:34:37 PM
The PDF viewer works quite nice, with the other I get always an error...

how ever.

One Problem with the PDF viewer. If I'm not closing, the PDF keeps still open and overlays the screen...!?  ??? Did I miss something I have to add?
: Re: PDF Viewing - MIME application/pdf
: potion May 09, 2012, 10:04:34 AM
Occasionally the Internet Content (MIME) Type of the document does not match the extension.  For example, for a file somefile.pdf the type should be application/pdf, but instead it is shown as something else, like application/octet-stream or just application/ , which then means that it cannot be viewed with the embedded PDF viewer.

Short Question: How can I change the type?