我正在使用核心PHP运行我的wkhtmltopdf代码并且它工作正常,它正在创建pdf但是现在我已经在drupal中创建了一个模块并运行相同的代码,如果我直接使用saveas方法但是如果我这样做它是有效的使用send()方法(生成弹出窗口打开或保存pdf)它没有显示弹出窗口。
以下是我的代码 -
function wkhtmltopdf_form($form, $form_state)
{
$form['table'] = array(
'#theme' => 'table',
// '#header' => array(t('Column1'), t('Column2')),
'#rows' => array(
array('Name :', 'Kala Aundhkar','Age:', '24'),
array('Address:', 'Hill Road','City:','mumbai'),
array('State:', 'Maharashtra','Country:','India'),
),
);
$form['export']=array(
'#type' => 'submit',
'#value' => t('Export'),
'#submit' => array('wkhtmltopdf_table_form_export'), // <-- make this an array
);
return $form;
}
function my_module_table_form_export($form,&$form_state)
{
$file=DRUPAL_ROOT . '/' . drupal_get_path('module', my_module) . "/lib/WkHtmlToPdf.php";
if (is_file($file)) {
require_once $file;
}
$date = date("Y-m-d");
$pdfNm = 'testPDF' . $date . '.pdf';
// Create a new WKHtmlToPdf object with some global PDF options
$pdf = new WkHtmlToPdf(array(
'use-xserver',
'no-outline', // Make Chrome not complain
'margin-right' => 0,
'margin-left' => 0,
'page-size'=>'A4'
// 'margin-top' => '5mm',
// 'margin-bottom' => '5mm',
));
$pdf->addPage('http://www.google.com'); //we can also pass html file for conversion
$pdf->send($pdfNm);
}
WkHtmlToPdf.php中的send()方法如下:
public function send($filename=null)
{
if(($pdfFile = $this->getPdfFilename())===false)
return false;
header('Pragma: public');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Content-Type: application/pdf');
header('Content-Transfer-Encoding: binary');
header('Content-Length: '.filesize($pdfFile));
if($filename!==null)
header("Content-Disposition: attachment; filename=\"$filename\"");
readfile($pdfFile);
return true;
}
现在,当我运行此代码时,它不会创建保存pdf的弹出窗口。