Summary: Embed PDF, PPT, DOC, and TIFF files in a wiki page using Google Viewer
Version: 2010-05-16
Prerequisites:
Status:
Questions answered by this recipe
How can I embed PDF, PPT, DOC, or TIFF files in a wiki page?
Description
GoogleViewer supports embedding PDF documents, PowerPoint presentations, Microsoft Word .doc files, and TIFF files on a wiki page. They may be hosted on your own wiki website, or on GoogleDocs, or elsewhere on the web. It is not necessary to have a Google account to use the viewer services. For more info on Google Viewer, visit http://docs.google.com/viewer.
A Note on Supported Formats
The GoogleViewer page listed above states that "PDF documents, PowerPoint presentations, and TIFF files are supported." In addition, experimentation shows that it also seems to support DOC and ODT files as well. RTF files, however, seem to fail, and quite strangely I've found that PPT files exported from GoogleDocs occasionally seem to fail, while the same PPT opened and then saved with OpenOffice/NeoOffice works! So, if at first you don't succeed, save save again ... from another program, or in a different format. overtones99 December 22, 2010, at 07:16 PM
Demo: http://plus1plus1plus.org/Resources/PmWiki-GoogleViewer
Notes
To install, include GoogleViewer.phpΔ in config.php:
include_once("$FarmD/cookbook/GoogleViewer.php");
You must also define $UploadUrlFmt (the path to your uploads directory) and $group in config.php before including your recipe. If these haven't already been defined, your installation may look like:
$group = PageVar($pagename,'$Group');
$UploadUrlFmt = "http://mysite.com/pmwiki/uploads";
include_once("$FarmD/cookbook/GoogleViewer.php");
The most basic syntax is:
(:googleviewer myfile.pdf:)
The filename can be provided in several formats:
(:googleviewer http://blah.com/myfile.pdf:) - view a file hosted on an external site, using a full url
(:googleviewer testfile.pdf:) - view a file in the current group
(:googleviewer Group./testfile.pdf:) OR (:googleviewer Group/testfile.pdf:) - view a file in another group on the same wiki
4 optional parameters are available:
(:googleviewer myfile.pdf width=... height=... embedded=... style=...:)
- width - (default: 600) - can be included as a pixel-value (i.e. width="500"), or as a fluid percentage value (i.e. width="100%")
- height - (default: 780) - only seems to respond intuitively to a pixel-value: i.e. height="600"
- embedded - (default: true) - when set to 'true', the pdf shows up as a single page, and all icons are small and listed at the top; when set to 'false', more of the GoogleDocs interface emerges, such as the "download" and "print" links at the top, a large GoogleDocs icon/link, and most notably the column on the right showing thumbnails of all the pages, with navigation tools. This latter setting is probably most useful for a long document where nonlinear navigation is of importance.
- style - css style information can be provided, i.e. style="border:5px dotted red;"
To define different wiki-wide default values, declare something like this in config.php before including the recipe:
$GoogleViewerDefaults['width'] = '100%';
$GoogleViewerDefaults['height'] = '1000';
For the sake of comparison (not competition : ) to other recipes or pdf-viewing services, it's worth pointing out that:
PROS
- this recipe does NOT require visitors to have the Adobe PDF Viewer Plugin installed in their browser (as does ViewPDF)
- the files you want to view can be stored anywhere, and needn't be uploaded to Google Docs or even to your own site (I may be incorrect, but it seems that most services like Scribd require you to upload files to their site in order to then embed and view them on yours...)
- the GoogleViewer displays PDFs, PowerPoints, .doc, and TIFF files, while ViewPDF only display PDFs
CONS
- some of the fonts look absolutely horrible!
- many of the images seem to be majorly pixelated, dithered, ugly - YUCK! : (
Release notes
- 2010-05-16 - added parameter "embedded="
- 2010-01-23c - fixed bug that prevented recipe from working for users with per-page-uploads (
$UploadFileFmt = '$Group/$Name'; the globals $group and $UploadUrlFmt are no longer needed for this recipe
- 2010-01-23 - initial release (overtones99) (feel free to improve upon this recipe)
See also
- Scribd - Embed Scribd documents & pdfs on a webpage
- ViewPDF - recipe by Peter Bowers that uses the Adobe PDF Plugin to embed pdfs
- PmDocConvert - PmDocConvert makes it easy to upload and display formats that can be handled by OpenOffice.org on a PmWiki page.
Contributors
Comments
Cool. Could you please post a link to a demo?
yep: http://plus1plus1plus.org/Resources/PmWiki-GoogleViewer
Susan F.: Functional PDF Viewer
- Added note (Susan F.): I just noticed this, when you are logged into your Google Account, the Google Viewer trys to access Google's Secure Login page. This happens in IE / XP. There is also an issue with users on Chrome 10xxx / Vista where the Google Viewer displays a Google login on half the Google Viewer.
- I assume this is the code that calls the login: src="http://docs.google.com/viewer?url='.$fileurl.'&embedded='.$args['embedded'].'" width="'.$args['width'].'" height="'.$args['height'].'" style="'.$args['style'].'
Hi Susan. Unfortunately I'm not sure it's the recipe's fault. If you check out the GoogleBlog blog for GoogleViewer (http://googledocs.blogspot.com/2009/09/view-online-files-using-google-docs.html), you'll see in the comment section, especially in the last 6-8 months, a lot of complaints from people also receiving login windows when they shouldn't. I'm subscribed to that blog, and from the frequency of the same complaints, very similar to the one you've mentioned above, I'm not sure how much Google is working to improve this tool. The code above just helps plug in the correct values for the url in the iframe. And if you look at the source code on your wiki page (which is displaying fine for me on OSX/Chrome), you'll see no weird login stuff being plugged in. overtones99 April 07, 2011, at 03:31 PM
- New issue: Attempt to access Google secure login displays (status bar) when accessing another secure access system. I have deleted the file and reinstalled a new copy. This seems to have temporarily resolved the issue.
- New issue: This may not be related to the Google Viewer, but it is worth the note. Replacing the PDF file on a server with a new document causes a delay in the representation of the document image in the viewer itself.
I tried the recipe but it did not work for me. I am organizing my uploads by page and have $UploadPrefixFmt = '/$Group/$Name'; enabled in my config file. I am assuming this has something to do with it... Any ideas?
Sameer 23 Jan 2010
hi. here is a version that attempts to fix this problem: GoogleViewer-2010-01-23c.phpΔ . would some folks mind trying this to see if it works? it does on my system, for both per-group and per-page uploads, but not on Sameer's. overtones99
the overtones99 version worked for me, thank you very much! I'm doing uploads differently but had them enabled... easier to use new .php than tinker w/ my settings. Thanks!
User notes +2: If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.