/[drupal]/contributions/modules/dompdf/dompdf.module
ViewVC logotype

Contents of /contributions/modules/dompdf/dompdf.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.2 - (show annotations) (download) (as text)
Fri Jul 31 17:05:05 2009 UTC (3 months, 3 weeks ago) by mlsamuelson
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-6--1
Changes since 1.1: +101 -3 lines
File MIME type: text/x-php
Bringing dompdf HEAD up to date with current working copy in preparation of creating a Drupal 6 branch.
1 <?php
2 // $Id: dompdf.module,v 1.1.2.7 2008/01/29 03:29:07 jrbeeman Exp $
3
4 /**
5 * Stream a PDF to the browser using
6 *
7 * @param $html
8 * HTML to use to render the PDF
9 * @param $filename
10 * The desired filename for the streamed PDF
11 * @param $directives
12 * An optional array of directives to run on the DOMPDF object before streaming it to the browser.
13 * Possible directives are: set_base_path, set_host, set_paper, set_protocol
14 * @see <a href="http://www.digitaljunkies.ca/dompdf/usage.php#dompdf_reference">DOMPDF Class Reference</a>
15 *
16 * Example usage:
17 * <?php
18 * $html = '<h1>Hello World</h1>';
19 * $filename = 'hello_world.pdf';
20 * $directives = array(
21 * 'set_protocol' => 'file://',
22 * 'set_paper' => array('letter', 'landscape')
23 * );
24 * ?>
25 */
26 function dompdf_stream_pdf($html, $filename, $directives = array()) {
27 require_once drupal_get_path('module', 'dompdf') . '/dompdf/dompdf_config.inc.php';
28 $allowed_directives = array(
29 'set_base_path',
30 'set_host',
31 'set_paper',
32 'set_protocol',
33 );
34
35 $dompdf = new DOMPDF();
36 $dompdf->load_html($html);
37
38 foreach ($directives as $directive => $params) {
39 if (in_array($directive, $allowed_directives)) {
40 call_user_func_array(array($dompdf, $directive), $params);
41 }
42 }
43
44 $dompdf->render();
45 $dompdf->stream($filename);
46 }
47
48
49 /**
50 * Implementation of hook_views_api()
51 */
52 function dompdf_views_api() {
53 return array(
54 'api' => 2,
55 );
56 }
57
58
59 /**
60 * Menu callback for print a view
61 */
62 function dompdf_print_view($view_name) {
63 $view = views_get_view($view_name);
64
65
66 // Theme our view's output.
67 $html = theme('dompdf_print_view', $view);
68
69 // Stream to PDF.
70 $filename = $view_name .".pdf";
71 dompdf_stream_pdf($html, $filename);
72 }
73
74 /**
75 * Implementation of hook_theme().
76 *
77 */
78 function dompdf_theme($existing, $type, $theme, $path) {
79 return array(
80 'dompdf_print_view' => array(
81 'arguments' => array('view' => NULL,),
82 ),
83 );
84 }
85
86
87 /**
88 * Theme function for printing a view
89 */
90 function theme_dompdf_print_view($view) {
91 global $base_url;
92
93 // TODO keep "edit, export, clone" links out of output.
94 // TODO keep exposed forms out, too.
95
96 // Tweak the view before output here. (Haven't tested effectiveness of this.)
97
98 // DEBUG
99 // To debug, comment out the dompdf_stream_pdf() call in dompdf_print_view().
100 // Then you can output $view here to check your manipulations.
101 // dpm($view);
102
103 // Tell views to build the view content.
104 $content = $view->preview('default');
105 $body .= $content;
106
107
108 $html = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
109 $html .= '<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">';
110 $html .= "<head>\n<title>". $title ."</title>\n";
111 $html .= '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
112 $html .= '<base href="'. $base_url .'/" />' . "\n";
113 $html .= "<style type=\"text/css\">\n@import url(". $base_url ."/misc/print.css);\n</style>\n";
114 $html .= "</head>\n<body>\n". $body ."\n</body>\n</html>\n";
115 return $html;
116 }

  ViewVC Help
Powered by ViewVC 1.1.2