Generate PDF with wkhtmltopdf after batch finished I would like to generate a pdf with wkhtmltopdf at the end of my batch.

I integrate the generation in the callback function but it does not offer me the download of the file

This is my finished function:

function csm_generate_pdf_finished($success, $results, $operations) {
  $message = 'some errors';

  if ($success) {
    if (($library = libraries_load('phpwkhtmltopdf')) &amp;&amp; !empty($library['loaded'])) {
      $pdf = new WkHtmlToPdf();
      $html = $results['data'];
      $start = $results['start'];
      $end = $results['end'];
      $pdf-&gt;addPage( $html );

      $filename = 'document_'.$start.'_'.$end.'.pdf';

      $pdf-&gt;send($filename);

      $message = 'Generation PDF ok';
    }
  }
  drupal_set_message($message);
}
The Finish function runs in the background and you can't return file there, the solution for your case is redirected to another page and create and return pdf file there.

something like drupal_goto('your_custom_url_to_generate');