Overview

Packages

  • Jonah
  • None

Classes

  • Jonah
  • Jonah_Api
  • Jonah_Block_Latest
  • Jonah_Driver
  • Jonah_Driver_Sql
  • Jonah_Exception
  • Jonah_Factory_Driver
  • Jonah_Form_Feed
  • Jonah_Form_Story
  • Jonah_Test
  • Jonah_View_ChannelDelete
  • Jonah_View_ChannelEdit
  • Jonah_View_ChannelList
  • Jonah_View_StoryDelete
  • Jonah_View_StoryEdit
  • Jonah_View_StoryList
  • Jonah_View_StoryPdf
  • Jonah_View_StoryView
  • Jonah_View_TagSearchList
  • Overview
  • Package
  • Class
  • Tree
 1: <?php
 2: /**
 3:  * Copyright 2003-2012 Horde LLC (http://www.horde.org/)
 4:  *
 5:  * See the enclosed file LICENSE for license information (BSD). If you
 6:  * did not receive this file, see http://cvs.horde.org/co.php/jonah/LICENSE.
 7:  *
 8:  * @author Chuck Hagenbuch <chuck@horde.org>
 9:  * @package Jonah
10:  */
11: class Jonah_View_StoryPdf extends Jonah_View
12: {
13:     public function run()
14:     {
15:         extract($this->_params, EXTR_REFS);
16: 
17:         $driver = $GLOBALS['injector']->getInstance('Jonah_Driver');
18:         if (!$story_id) {
19:             try {
20:                 $story_id = $GLOBALS['injector']->getInstance('Jonah_Driver')->getLatestStoryId($channel_id);
21:             } catch (Exception $e) {
22:                 $this->_exit($e->getMessage());
23:             }
24:         }
25:         try {
26:             $story = $driver->getStory($channel_id, $story_id, !$browser->isRobot());
27:         } catch (Exception $e) {
28:             $this->_exit($e->getMessage());
29:         }
30: 
31:         // Convert the body from HTML to text if necessary.
32:         if (!empty($story['body_type']) && $story['body_type'] == 'richtext') {
33:             $story['body'] = $GLOBALS['injector']->getInstance('Horde_Core_Factory_TextFilter')->filter($story['body'], 'html2text');
34:         }
35: 
36:         // Set up the PDF object.
37:         $pdf = new Horde_Pdf_Writer(array('format' => 'Letter', 'unit' => 'pt'));
38:         $pdf->setMargins(50, 50);
39: 
40:         // Enable automatic page breaks.
41:         $pdf->setAutoPageBreak(true, 50);
42: 
43:         // Start the document.
44:         $pdf->open();
45: 
46:         // Start a page.
47:         $pdf->addPage();
48: 
49:         // Publication date.
50:         if (!empty($story['published_date'])) {
51:             $pdf->setFont('Times', 'B', 14);
52:             $pdf->cell(0, 14, $story['published_date'], 0, 1);
53:             $pdf->newLine(10);
54:         }
55: 
56:         // Write the header in Times 24 Bold.
57:         $pdf->setFont('Times', 'B', 24);
58:         $pdf->multiCell(0, 24, $story['title'], 'B', 1);
59:         $pdf->newLine(20);
60: 
61:         // Write the story body in Times 14.
62:         $pdf->setFont('Times', '', 14);
63:         $pdf->write(14, $story['body']);
64: 
65:         // Output the generated PDF.
66:         $browser->downloadHeaders($story['title'] . '.pdf', 'application/pdf');
67:         echo $pdf->getOutput();
68:     }
69: 
70: }
API documentation generated by ApiGen