Hi!
I suggest to add one string to extend flexibility of your module:

function _pdf_using_mpdf_generator($html, $filename = NULL) {
...
$mpdf = new mPDF(...)
...
  // Ability to alter mPDF settings by other modules.
  drupal_alter('mpdf_document', $mpdf);

  $mpdf->WriteHTML($html);
...
}

After that we can implement hook_alter in the custom module to change all mPDF setting we want, for example:

function mymodule_mpdf_document_alter(&$mpdf_object) {
  if ($some_condition) {
    unset($mpdf_object->HTMLHeader);
    unset($mpdf_object->HTMLFooter);
  }
}

And etc.

Comments

nikita petrov’s picture

Status: Active » Needs review
StatusFileSize
new725 bytes

Here is the patch for that functionlity.

nikita petrov’s picture

Issue summary: View changes
salnoob’s picture

Another option would be to provide a more robust api function that can accept an array of options.
For example, it could take:

$options = array(
  'header' => '<h6> HEADERS UP !! </h6>',
  'footer' => '<h5> FOOTERS DOWN !! </h5>',
  'title' => "Testing Title",
  'save_option' => 'I',
  'css_path' => $module_path . '/theme',
  'css_file' => 'some_node_pdf.css', 
  'margin_header' => 4,
  'margin_footer' => 4,
  'margin_left' => 10,
  'margin_right' => 10,
  'font_size' => 8,
  'watermark_option' => 'text',
  'watermark_text' => 'my watermark',
  'watermark_opacity' => '0.2', 
//  'page_size' => 'Ledger'
);

Within the code I just added a statement wherever there are 'variable_get' calls. This is a hopefully temporary fix though.

$margin_top = isset($options['margin_top']) ? $options['margin_top'] : variable_get('pdf_using_mpdf_margin_top', 16);
srjosh’s picture

Status: Needs review » Reviewed & tested by the community

Works well for me.

nevergone’s picture

Status: Reviewed & tested by the community » Closed (duplicate)
Related issues: +#2400245: Hooks to alter PDF config/attributes from other modules