Only in dompdf: dompdf diff -urp dompdf-5.x-1.x-dev/dompdf.module dompdf/dompdf.module --- dompdf-5.x-1.x-dev/dompdf.module 2008-01-28 19:29:07.000000000 -0800 +++ dompdf/dompdf.module 2008-02-05 22:44:48.000000000 -0800 @@ -14,7 +14,7 @@ * @see DOMPDF Class Reference * * Example usage: - * Hello World'; * $filename = 'hello_world.pdf'; * $directives = array( @@ -23,26 +23,27 @@ * ); * ?> */ -function dompdf_stream_pdf($html, $filename, $directives = array()) { +function dompdf_stream_pdf($html, $filename, $directives = array(), $id='', $type='views') { require_once drupal_get_path('module', 'dompdf') . '/dompdf/dompdf_config.inc.php'; + $settings = variable_get("dompdf_{$type}_settings_". $id, array()); $allowed_directives = array( - 'set_base_path', - 'set_host', - 'set_paper', + 'set_base_path', + 'set_host', + 'set_paper', 'set_protocol', ); - + $dompdf = new DOMPDF(); $dompdf->load_html($html); - + foreach ($directives as $directive => $params) { if (in_array($directive, $allowed_directives)) { call_user_func_array(array($dompdf, $directive), $params); } } - + $dompdf->render(); - $dompdf->stream($filename); + $dompdf->stream($filename, array("Attachment" => (!empty($settings['attachment'])? 1:0))); } @@ -51,7 +52,7 @@ function dompdf_stream_pdf($html, $filen */ function dompdf_menu($may_cache) { $items = array(); - + if (!$may_cache) { // Provide "Print PDF" links from views, if they are configured to do so. if (module_exists('views_ui')) { @@ -65,7 +66,7 @@ function dompdf_menu($may_cache) { foreach($filters as $key => $filter) { $query .= "filter$key=". $filter['filter'] ."&"; } - + $items[] = array( 'path' => "$url/pdf", 'query' => $query, @@ -79,7 +80,35 @@ function dompdf_menu($may_cache) { } } } - + + /* + + $name = $form['#node_type']->type; + $settings = variable_get('dompdf_node_settings_'.$name, array()); + */ + + $type=arg(0); + $nid=arg(1); + + if ($type == 'node' && is_numeric($nid)){ + $node=node_load($nid); + $settings = variable_get('dompdf_node_settings_'. $node->type, array()); + + if ($settings['print']) { + $items[] = array( + 'path' => "node/$nid/pdf", + 'title' => t('Print PDF'), + 'callback' => 'dompdf_print_node', + 'callback arguments' => array($nid), + 'type' => MENU_LOCAL_TASK, + 'weight' => 10, + ); + } + + } + + + return $items; } @@ -91,17 +120,78 @@ function dompdf_form_alter($form_id, &$f if ($form_id == 'views_edit_view') { dompdf_alter_views_edit_view($form_id, $form); } + + if ($form_id=='node_type_form'){ + dompdf_alter_node_type($form_id, $form); + } + +} + +/** + * Alter the node_type form + */ +function dompdf_alter_node_type($form_id, &$form) { + $name = $form['#node_type']->type; + $settings = variable_get('dompdf_node_settings_'.$name, array()); + $form['#submit']['dompdf_edit_node_submit'] = array(); + + $form['workflow']['dompdf'] = array( + '#type' => 'fieldset', + '#title' => t('DOMPDF'), + '#description' => t('Options for printing the view to PDF'), + '#collapsible' => TRUE, + '#collapsed' => TRUE, + '#tree' => TRUE, + ); + $form['workflow']['dompdf']['print'] = array( + '#type' => 'checkbox', + '#title' => t('Provide link to print as PDF'), + '#default_value' => $settings['print'], + ); + $form['workflow']['dompdf']['header'] = array( + '#type' => 'textarea', + '#title' => t('Header'), + '#description' => t('Text to insert at the head of the view when printing to PDF. Useful for inserting additional styles, logos, etc. Optional. Always rendered as Full HTML inside a div with the class "dompdf-views-header".'), + '#default_value' => $settings['header'], + '#cols' => 60, + '#rows' => 5, + ); + $form['workflow']['dompdf']['footer'] = array( + '#type' => 'textarea', + '#title' => t('Footer'), + '#description' => t('Text to insert at the footer of the view when printing to PDF. Useful for inserting additional styles, logos, etc. Optional. Always rendered as Full HTML inside a div with the class "dompdf-views-footer".'), + '#default_value' => $settings['footer'], + '#cols' => 60, + '#rows' => 5, + ); + + $form['workflow']['dompdf']['attachment'] = array( + '#type' => 'checkbox', + '#title' => t('Attachment'), + '#description' => t('Check this to display the PDF as an attachment (download) Uncheck for inline.'), + '#default_value' => $settings['attachment'], + ); } + +/** + * Submit handler for node content type edit form + */ +function dompdf_edit_node_submit($form_id, $form_values) { + variable_set('dompdf_node_settings_'. $form_values['type'], $form_values['dompdf']); +} + + + /** * Alter the views_edit_view form */ function dompdf_alter_views_edit_view($form_id, &$form) { $name = $form['basic-info']['name']['#default_value']; $settings = variable_get('dompdf_views_settings_'.$name, array()); - $form['#submit']['dompdf_views_edit_view_submit'] = array(); - + $form['#submit']['dompdf_edit_node_submit'] = array(); + $form['page-info']['dompdf'] = array( '#type' => 'fieldset', '#title' => t('DOMPDF'), @@ -131,6 +221,13 @@ function dompdf_alter_views_edit_view($f '#cols' => 60, '#rows' => 5, ); + + $form['page-info']['dompdf']['attachment'] = array( + '#type' => 'checkbox', + '#title' => t('Attachment'), + '#description' => t('Check this to display the PDF as an attachment (download) Uncheck for inline.'), + '#default_value' => $settings['attachment'], + ); } @@ -148,14 +245,14 @@ function dompdf_views_edit_view_submit($ function dompdf_print_view($view_name) { $view = views_get_view($view_name); $settings = variable_get('dompdf_views_settings_'. $view_name, NULL); - + // Remove unusable (and unprintable) sortable icons if (count($view->field)) { foreach($view->field as $key => $field) { $view->field[$key]['sortable'] = 0; } } - + // Build the content $content = ''; if ($settings['header']) { @@ -165,11 +262,35 @@ function dompdf_print_view($view_name) { if ($settings['footer']) { $content .= theme('dompdf_view_footer', $settings['footer']); } - + $title = $view->page_title ? $view->page_title : $view->name; $html = theme('dompdf_print_view', $content, $title); $filename = $view_name .".pdf"; - dompdf_stream_pdf($html, $filename); + dompdf_stream_pdf($html, $filename,array(), $view_name, 'views'); +} + +/** + * Menu callback for print a node + */ +function dompdf_print_node($nid) { + $node = node_load($nid); + $settings = variable_get('dompdf_node_settings_'.$node->type, array()); + + // Build the content + $content = ''; + if ($settings['header']) { + $content .= theme('dompdf_node_header', $settings['header']); + } + $content .= node_view($node); + + if ($settings['footer']) { + $content .= theme('dompdf_node_footer', $settings['footer']); + } + + $title = $node->title; + $html = theme('dompdf_print_node', $content, $title); + $filename = $node->type .".pdf"; + dompdf_stream_pdf($html, $filename,array(), $node->type,'node'); } @@ -196,7 +317,7 @@ function theme_dompdf_print_view($conten global $base_url; $body = "