Index: modules/pdfview/CHANGELOG
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/pdfview/CHANGELOG,v
retrieving revision 1.6
diff -u -r1.6 CHANGELOG
--- modules/pdfview/CHANGELOG	30 Mar 2005 21:48:28 -0000	1.6
+++ modules/pdfview/CHANGELOG	16 Mar 2006 07:07:31 -0000
@@ -1,3 +1,7 @@
+15. March 2006
+==============
+Rewritten from scratch using code from print.module.
+
 30. March 2005
 ==============
 Partially updated support for api changes.
Index: modules/pdfview/INSTALL
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/pdfview/INSTALL,v
retrieving revision 1.4
diff -u -r1.4 INSTALL
--- modules/pdfview/INSTALL	5 Nov 2004 19:44:00 -0000	1.4
+++ modules/pdfview/INSTALL	16 Mar 2006 07:11:12 -0000
@@ -1,5 +1,5 @@
 1) Copy pdfview.module to module/pdfview directory of your site.
-2) Retrieve FPDF from the location given in README.txt.
-3) Copy the entire directory structure from the archive to modules/pdfview/fpdf.
+2) Retrieve html2fpdf from the location given in README.txt.
+3) Copy the entire directory structure from the archive to modules/pdfview/html2fpdf.
 4) Enable the module in site configuration modules.
 5) Set permissions for access.
Index: modules/pdfview/README.txt
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/pdfview/README.txt,v
retrieving revision 1.1
diff -u -r1.1 README.txt
--- modules/pdfview/README.txt	13 Oct 2004 13:01:41 -0000	1.1
+++ modules/pdfview/README.txt	16 Mar 2006 07:11:03 -0000
@@ -1,10 +1,8 @@
 A module to generate a pdf files from nodes.
 
-It relies on FPDF, which is a freeware PHP class.
-It can be found here: http://www.fpdf.org
+It relies on html2pdf, which is a freeware PHP class.
+It can be found here: http://html2fpdf.sourceforge.net/
 
 The FPDF distribution comes with instructions for handling custom fonts and
 encodings.  Please refer to their documentation before posting a feature or
 support requestion on http://drupal.org
-
-Send bug reports to gerhard@killesreiter.de.
Index: modules/pdfview/pdfview.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/pdfview/pdfview.module,v
retrieving revision 1.18
diff -u -r1.18 pdfview.module
--- modules/pdfview/pdfview.module	28 Oct 2005 20:36:56 -0000	1.18
+++ modules/pdfview/pdfview.module	16 Mar 2006 14:29:37 -0000
@@ -1,145 +1,159 @@
 <?php
-// $Id: pdfview.module,v 1.18 2005/10/28 20:36:56 urbanfalcon Exp $
+/* $Id */
 
 /**
- * Last tested:
- * By: Gabriel Sjoberg (aim:banditbuddhist email:xabbu-at-cox-dot-net drupal: TheLibrarian)
- * Running At: http://www.nosir.org
- * Date: 22 May 2004
- * Drupal Version: cvs (22 May 2004)
- */
- 
-/**
- * @todo Expand the help text.
- * @todo Comment the source code for this module.
- * @todo Improve support for images.
- * @todo Add support for printing entire books to pdf (this may have to be implemented in book.module).
- * @todo Add support for specifying exactly which types or which specific nodes users should be allowed to output as pdf.
- * @todo Move "" over to '' where applicable
- * @todo All _hook() functions should take in every parameter, even if they aren't used.
+ * @file
+ * Renders nodes as PDF files for download
  */
 
+/********************************************************************
+ * Drupal Hooks :: Overview
+ ********************************************************************/
 
-function pdfview_help($section = 'admin/help#pdfview') {
-  $output = '';
+/**
+ * Implementation of hook_help().
+ */
+function pdfview_help($section) {
   switch ($section) {
-    case 'admin/help#pdfview':
-      $output = t('View your nodes as pdf.');
-      break;
     case 'admin/modules#description':
-      $output = t('Enables users to view nodes as pdf.');
-      break;
+      return t('Enables users to view nodes as pdf.');
   }
-  return $output;
 }
 
-function pdfview_pdf ($node = 0, $depth = 1) {
-  if (user_access('access content as pdf')) {
-	//now using HTML2FPDF for more accuracy  
-    //require_once('pdf.class.php');
-	
-	require_once('html2fpdf/html2fpdf.php'); 
-
-    $pageheight = 770;
-    $pagewidth = 540;
-    
-	//now using HTML2FPDF for more accuracy
-    //$pdf = new PDF();
-	$pdf = new HTML2FPDF();
-    $pdf->Open();
-    $pdf->AddPage();
-	
-	echo $node->type;
-	
-	$node = node_load(array("nid" => $node));
-	//$text = $node->body;
-	//$p = explode("\n", $text);
-	$output = $node->body;
-	$output = explode("\n", $output);
-	
-	$title = $node->title;
-	$pdf->SetFont('helvetica','B',15);
-	$w = $pdf->GetStringWidth($title)+6;
-	$pdf->SetX((210-$w)/2);
-	$pdf->SetLineWidth(1);
-	$pdf->Cell($w,9,$title,0,1,'C');
-	$pdf->Ln(5);
-
-	$author = 'By '. strip_tags(format_name($node));
-	$pdf->SetFont('helvetica','BI',10);
-	$pdf->MultiCell(0, 5, $author, 0, 'L', 0);
-
-	$published = 'Published: '. format_date($node->created, 'small');
-	$pdf->SetFont('', '', 10);
-	$pdf->MultiCell(0, 5, $published, 0, 'L', 0);
-	$pdf->Ln(5);
-
-    // node type specific stuff.
-    if ($node->type == "image") {
-		$image = image_display($node);
-		$pdf->WriteHTML($image);
-		}
-
-    // Write the node's body to the PDF document.
-	$pdf->SetFont('helvetica', '', 11);
-	$param["height"] = 10;
-	foreach ($output as $one) {
-		$pdf->WriteHTML($one);
-		}
-
-    $filename = strtr(strip_tags($node->title), " .,?!&#", "_______");
-    header("Content-Disposition: attachment; filename=". $filename .".pdf");
-    header("Content-Type: application/pdf");
+/**
+ * Implementation of hook_menu().
+ */
+function pdfview_menu($may_cache) {
+  $items = array();
+  if (!$may_cache) {
+    $items[] = array('path' => 'node/'. arg(1) .'/pdf', 'title' => t('view as pdf'),
+      'callback' => 'pdfview_node_controller',
+      'access' => user_access('access content as pdf'),
+      'type' => MENU_CALLBACK
+    );
+
+    $items[] = array('path' => 'pdfview/'. arg(1), 'title' => t('view as pdf'),
+      'callback' => 'pdfview_node_controller',
+      'access' => user_access('access content as pdf'),
+      'type' => MENU_CALLBACK
+    );
+
+    $items[] = array('path' => 'pdf', 'title' => t('pdf version'),
+      'callback' => 'pdfview_controller',
+      'access' => user_access('access content as pdf'),
+      'type' => MENU_CALLBACK
+    );
+  }
+  return $items;
+}
+
+/********************************************************************
+ * Drupal Hooks :: Core
+ ********************************************************************/
+
+/**
+ * Implementation of hook_link().
+ */
+function pdfview_link($type, $node = 0, $main) {
+  $links = array();
 
-    print $pdf->Output($filename.'.pdf', 'D');
-    die();
+  if ($type == 'node' && !isset($node->parent)) && $main == 0) {
+    $links[] = theme('pdfview_link', $node);
   }
+
+  return $links;
 }
 
 function pdfview_perm() {
   return array("access content as pdf");
 }
 
-function pdfview_page($nid) {
-  if (user_access('access content as pdf')) {
-    if ($node != null)
-      pdfview_pdf($nid);
-    else
-      switch (arg(1)) {
-        case 'view':
-          if (arg(2)) {
-            pdfview_pdf(arg(2));
-          }
-          break;
-        default:
-          $output = t('You must specify which node you wish to view as pdf.');
-          print theme('page', $output);
-          break;
-      }
-  }
-  else {
-    print theme('page', t("Access Denied"), message_access());
+/********************************************************************
+ * Module Functions :: Controllers
+ ********************************************************************/
+
+function pdfview_node_controller() {
+  $nid = arg(1);
+  if (is_numeric($nid)) {
+    pdfview_generate_node($nid);
   }
 }
 
-function pdfview_link($type, $node = null, $teaser = false) {
-  $links = array();
-  if (($type == "node") && (user_access("access content as pdf"))) {
-    $links[] = l(t("view as pdf"), "pdfview/view/$node->nid", array("title" => t("View and print node as pdf.")));
+function pdfview_controller($module) {
+  $f = 'pdfview_generate_'. $module;
+
+  if (function_exists($f)) {
+    $f();
   }
-  
-  return $links;
 }
 
-function pdfview_menu($may_cache) {
-  $items = array();
+/********************************************************************
+ * Module Functions
+ ********************************************************************/
+
+/**
+ * Outputs a pdf file.
+ */
+function pdfview_generate_node($nid) {
+  global $base_url;
+
+  $node = node_load($nid);
+	require_once(drupal_get_path('module', 'pdfview') . '/html2fpdf/html2fpdf.php'); 
+
+  $pageheight = 770;
+  $pagewidth = 540;
+  $pdf = new HTML2FPDF();
+  $pdf->Open();
+  $pdf->AddPage();
+
+  $output = $node->body;
+  $output = explode("\n", $output);
+
+  $title = $node->title;
+  $pdf->SetFont('helvetica','B',15);
+  $w = $pdf->GetStringWidth($title)+6;
+  $pdf->SetX((210-$w)/2);
+  $pdf->SetLineWidth(1);
+  $pdf->Cell($w,9,$title,0,1,'C');
+  $pdf->Ln(5);
   
-  $items[] = array('path' => 'pdfview', 'title' => t('view as pdf'),
-    'callback' => 'pdfview_page',
-    'callback arguments' => $node->nid,
-    'type' => MENU_CALLBACK,
-    'access' => user_access('access content as pdf'));
-  return $items;
+  $author = 'By '. strip_tags(theme('username', $node));
+  $pdf->SetFont('helvetica','BI',10);
+  $pdf->MultiCell(0, 5, $author, 0, 'L', 0);
+  
+  $published = 'Published: '. format_date($node->created, 'small');
+  $pdf->SetFont('', '', 10);
+  $pdf->MultiCell(0, 5, $published, 0, 'L', 0);
+  $pdf->Ln(5);
+  
+  // node type specific stuff.
+  if ($node->type == "image") {
+  	$image = image_display($node);
+  	$pdf->WriteHTML($image);
+  }
+  
+  // Write the node's body to the PDF document.
+  $pdf->SetFont('helvetica', '', 11);
+  $param["height"] = 10;
+  foreach ($output as $one) {
+  	$pdf->WriteHTML($one);
+	}
+
+  $filename = strtr(strip_tags($node->title), " .,?!&#", "_______");
+  drupal_set_header("Content-Disposition: attachment; filename=". $filename .".pdf");
+  drupal_set_header("Content-Type: application/pdf");
+
+  print $pdf->Output($filename.'.pdf', 'D');
 }
 
-?>
+/********************************************************************
+ * Module Functions :: Themeable Functions
+ ********************************************************************/
+
+function theme_pdfview_link($node) {
+  if (user_access('access content as pdf')) {
+    $attributes = array("title" => "Display a PDF version of this page.");
+    $links = l(t('download pdf'), "node/$node->nid/pdf", $attributes);
+  }
+  return $links;
+}
