0
我目前無法使dompdf工作。如果我包括dompdf流它不會出現任何東西。有人可以請建議/告訴我我如何獲得pdf保存。Symfony 2 + dompdf
public function indexAction()
{
$formData = new LimitedDirectApplication();
$flow = $this->get('shapehq.form.flow.limitedDirectApplication');
$flow->bind($formData);
$form = $flow->createForm();
if ($flow->isValid($form)) {
$flow->saveCurrentStepData($form);
if ($flow->nextStep()) {
// form for the next step
$form = $flow->createForm();
} else {
// flow finished
$em = $this->getDoctrine()->getManager();
$this->pdfAction($formData);
//var_dump($formData);die();
$em->persist($formData);
$em->flush();
$flow->reset(); // remove step data from the session
$this->sendSuccessEmail($formData);
return $this->redirect($this->generateUrl('shape_hq_greyfriars_sipp_homepage')); // redirect when done
}
}
return $this->render('ShapeHQGreyfriarsSippBundle:Application:directLimitedApplication.html.twig', array(
'form' => $form->createView(),
'flow' => $flow,
));
}
public function pdfAction($formData)
{
require_once('/var/www/src/backend/app/config/dompdf_config.inc.php');
$html = $this->renderView(
'ShapeHQGreyfriarsSippBundle:Application:DirectApplicationPDF.html.twig',
array('data' => $formData)
);
$dompdf = new \DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
//check whether there is a output folder
return new Response($dompdf->output(), 200, array(
'Content-Type' => 'application /pdf'
));
}
}
我渲染我喜歡這種形式的數據。
<p><strong>Personal Details</strong></p>
<p>Firstname: {{ data.firstname }}</p>
<p>Middle Name: {{ data.middlename }}</p>
<p>Surname: {{ data.lastname }}</p>
<p>Nationality: {{ data.nationality }}</p>
<p>DOB: {{ data.dateOfBirth | date }}</p>
<p>National Insurance Number: {{ data.nationalInsuranceNumber }}</p>
<p>Preferred retirement age: {{ data.preferredRetirementAge }}</p>
string '<h1>DIRECT</h1>
<p><strong>Personal Details</strong></p>
<p>Firstname: sham</p>
<p>Middle Name: </p>
<p>Surname: test</p>
<p>Nationality: British</p>
<p>DOB: January 10, 1985 00:00</p>
<p>National Insurance Number: QQ 12 34 56 A</p>
<p>Preferred retirement age: 65</p>
'
沒有想法,但你的代碼示例中你必須在內容類型的額外空間。也許只是在這個問題上的拼寫錯誤,但如果不是這可能會導致瀏覽器呈現問題。 – BrianS