In the form builder I have the following code.
$form['export_to_pdf'] = [ '#type' => 'submit', '#value' => $this->t('Pdf Format'), '#attributes' => array('name'=>'print_pdf',), '#ajax'=> array( 'callback' => '::exportPdf', 'event' => 'click', 'effect' => 'fade', 'prevent' => 'submit', 'progress' => array( 'type' => 'throbber', 'message' => t('Retrieving...'), ), ), ];
The callback function is the following one.
public function exportPdf(array &$form, FormStateInterface $form_state) { global $base_url; $url = "{$base_url}/pdf_templates/report.pdf"; $response = new AjaxResponse(); $response->addCommand(new RedirectCommand($url)); return $response; }
This works, but it doesn’t pop up the Open/Save file dialog. It redirects to the PDF file. How do I make the callback show the Open/Save file dialog so that the users can either open or save according to their wish?