Author Topic: PDF Viewing - MIME application/pdf  (Read 12915 times)

MicMac

  • Freshman
  • *
  • Posts: 15
  • Whow!
    • View Profile
PDF Viewing - MIME application/pdf
« on: 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



cabeza

  • Administrator
  • Hero Member
  • *****
  • Posts: 1004
    • View Profile
    • Feng Office
Re: PDF Viewing - MIME application/pdf
« Reply #1 on: February 24, 2010, 12:40:35 pm »
We can develop this is we find sponsors for the project.
Contact us at contact   @   fengoffice

altert

  • Newbie
  • *
  • Posts: 5
    • View Profile
Re: PDF Viewing - MIME application/pdf
« Reply #2 on: 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>';
   }
?>

jolivaresd

  • Freshman
  • *
  • Posts: 18
    • View Profile
Re: PDF Viewing - MIME application/pdf
« Reply #3 on: 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
Todos somos muy ignorantes. Lo que ocurre es que no todos ignoramos las mismas cosas.

franponce87

  • Administrator
  • Hero Member
  • *****
  • Posts: 1819
    • View Profile
    • Email
Re: PDF Viewing - MIME application/pdf
« Reply #4 on: 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
Would you like to install Feng Office Professional or Enterprise Edition in your servers? No problem! Read this article!

timveer

  • Freshman
  • *
  • Posts: 28
    • View Profile
Re: PDF Viewing - MIME application/pdf
« Reply #5 on: 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

potion

  • Freshman
  • *
  • Posts: 25
    • View Profile
    • WorkgroupBase
Re: PDF Viewing - MIME application/pdf
« Reply #6 on: 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)
Code: [Select]
<?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
« Last Edit: October 15, 2011, 05:57:42 pm by potion »

timveer

  • Freshman
  • *
  • Posts: 28
    • View Profile
Re: PDF Viewing - MIME application/pdf
« Reply #7 on: 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
« Last Edit: October 25, 2011, 11:24:34 pm by timveer »

franponce87

  • Administrator
  • Hero Member
  • *****
  • Posts: 1819
    • View Profile
    • Email
Re: PDF Viewing - MIME application/pdf
« Reply #8 on: 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
Would you like to install Feng Office Professional or Enterprise Edition in your servers? No problem! Read this article!

timveer

  • Freshman
  • *
  • Posts: 28
    • View Profile
Re: PDF Viewing - MIME application/pdf
« Reply #9 on: November 03, 2011, 05:08:39 pm »
Thanks Francisco  ;D

GGeczy

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Re: PDF Viewing - MIME application/pdf
« Reply #10 on: 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 :

 
Code: [Select]
<?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 :
 
Code: [Select]
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.

GGeczy

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Re: PDF Viewing - MIME application/pdf
« Reply #11 on: 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.


PSchnittger

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
Re: PDF Viewing - MIME application/pdf
« Reply #12 on: 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?

potion

  • Freshman
  • *
  • Posts: 25
    • View Profile
    • WorkgroupBase
Re: PDF Viewing - MIME application/pdf
« Reply #13 on: 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?