You are here

function invoice_view_pdf in Invoice 7

Same name and namespace in other branches
  1. 6 invoice.module \invoice_view_pdf()

Display the invoice in PDF format

1 call to invoice_view_pdf()
_invoice_api_invoice_get in ./invoice_api.inc
Handles GET request for the specified invoice ID
1 string reference to 'invoice_view_pdf'
invoice_menu in ./invoice.module
Implements hook_menu()

File

./invoice.module, line 1091
Invoice module

Code

function invoice_view_pdf($invoice_number) {
  $nid = db_query("SELECT nid FROM {invoice_invoices} WHERE iid = :iid", array(
    ':iid' => $invoice_number,
  ))
    ->fetchField();

  // include the dompdf library
  define('DOMPDF_ENABLE_PHP', TRUE);

  // Allow PHP code
  define('DOMPDF_ENABLE_REMOTE', TRUE);

  // Allow images defined by URL
  $error = _invoice_dompdf_include_lib();
  if ($error) {
    drupal_goto('node/' . $nid);
  }
  else {
    $node = node_load($nid);
    $html = _invoice_get_html($invoice_number, $node, 'pdf');
    $dompdf = new DOMPDF();
    $dompdf
      ->load_html($html);

    // @todo: Make configurable
    $dompdf
      ->set_paper('A4');
    $dompdf
      ->render();
    $dompdf
      ->stream(t('invoice') . '-' . $node->invoice['formatted_invoice_number'] . ".pdf", array(
      'Attachment' => 1,
    ));
    exit;
  }
}