Pdf viewing

From CONTENTdm Users Wiki

Jump to: navigation, search

Default pdf viewing in CONTENTdm has two quirks:

  1. When an individual item is a pdf the pdf is not displayed. Instead you get "click to access this item"
  2. Pdf viewing in compound objects for user on Macintosh or using Opera get "click to access this item"

Apply the following changes to fix these quirks.

Contents

[edit] View Individual Item PDF in iframe

To enable inline PDF viewing for single items (i.e. not compound objects) apply this patch to basic_view.php:

--- trunk/docs/cdm4/includes/basic_view.php	2006/04/25 02:27:15	214
+++ trunk/docs/cdm4/includes/basic_view.php	2006/05/01 23:40:31	218
@@ -74,7 +74,7 @@
 		<tr>
 			<td class="<?=$imageclass?>">
 
-			<table cellpadding="<?=S_RESULTS_PADDING_1?>" align="center" cellspacing="0" border="0">
+			<table cellpadding="<?=S_RESULTS_PADDING_1?>" align="center" cellspacing="0" border="0" width="100%">
 			<tr>
 				<td><span class="maintext">
 
@@ -116,6 +116,14 @@
 
 		if(in_array($type, $isBasicImage)){
 		echo '<img src="/cgi-bin/showfile.exe?CISOROOT='.$alias.'&CISOPTR='.$itnum.'" width="'.$width.'" height="'.$height.'" alt="">';
+		} elseif(strpos(strtolower($filename), '.pdf') > 0){
+ 		echo "<iframe width=\"100%\" height=\"500px\"" . 
+		  " src='/cgi-bin/showfile.exe?CISOROOT=" . 
+		  $alias . "&CISOPTR=" . $itnum . "'>";
+		/* The contents of an iframe will be displayed by browsers
+                   that cannot handle iframes. */
+		echo "<b><a href=\"/cgi-bin/showfile.exe?CISOROOT=".$alias."&CISOPTR=".$itnum."\" target=\"_blank\">".L_VIEW_ITEM."</a></b>";
+		echo "</iframe>";
 		} else {
 		echo "<b><a href=\"/cgi-bin/showfile.exe?CISOROOT=".$alias."&CISOPTR=".$itnum."\" target=\"_blank\">".L_VIEW_ITEM."</a></b>";
 		}

[edit] Whats going on here?

(This is the play by play of the changes listed above for those of you making them by hand.)

You should modify basic_view.php by removing lines starting with - and adding lines starting with +.

[edit] change 1: table width

The first pair of - and + change the width of the surrounding table to 100% so the iframe has room to display. You should be able to find the line you need to change around lines 74-77 in basic_view.php.

[edit] change 2: handle pdf files differently

The block of + lines describe eight lines you need to add to the file. Somewhere around line 116 of basic_view.php look for a line that says

  • default: (If you are running CONTENTdm version 4.2)
  • case "item_viewer.php": (If you are running CONTENTdm version 4.1)

You are adding a new elseif block to handle pdf files differently from other file types.

[edit] Enable pdf viewing for Macintosh and Opera users

To enable viewing of PDF files in compound objects for users running on Macintosh or with the Opera web browser.

Treat everyone the same: give them the pdf and let them deal with it. Most users will do just fine! I maintain that users of "OS X" and Opera are just as capable of handling pdf files as everybody else. Pdf files will open in the Preview application, which is included in OS X, from the browser. OS X users can also install browser plugins from either Adobe, or use Shubert|it PDF Browser Plugin (my recommendation).

Apply (remove lines with -, add lines with +) this patch to basic_view.php in the section under case "doc_viewer.php": for 4.2, or case "viewer.php": for 4.1:

 	} elseif(strpos(strtolower($filename), '.pdf') > 0){
-	echo "<script language=\"JavaScript\" type=\"text/javascript\">if(isMac || isOpera){document.write('<b><a href=\"/cgi-bin/showfile.exe?CISOROOT=".$alias."&CISOPTR=".$itnum."&filename=".substr($filename,strrpos($filename, "/")+1)."\" target=\"_blank\">".L_VIEW_ITEM."<\/a><\/b>');} else{location.replace('/cgi-bin/showfile.exe?CISOROOT=".$alias."&CISOPTR=".$itnum."')}</script>";
+		/*
+		 * Pdf pages of compound objects. Javascript forward.
+		 */
+		echo "<script>location.replace('/cgi-bin/showfile.exe?CISOROOT=".$alias."&CISOPTR=".$itnum."')</script>";
 	} else {

[edit] What is going on here?

This chunk of php is generating html and javascript code.

Remove the javascript if statement that checks for Mac or Opera.

(I don't think that pdf display should be handled using a client side redirect. However, fixing that would take more extensive changes to CONTENTdm.)

Personal tools