pdf 파일을 생성해야하는 컨트롤러가 있고 다른 사이트로 리디렉션해야하는 컨트롤러가 있습니다. Symfony2가 tcpdf를 사용하여 pdf 생성 후 새 페이지로 리디렉션하지 않습니다.
class DocuController extends Controller
{
public function indexAction() {
// some other code
if ($request->get('_add_document'))
{
$form->bindRequest($request);
$em = $this->getDoctrine()->getEntityManager();
$em->persist($document);
$em->flush();
if ($session->get('journey_id')!=false)
{
$relation = new DocumentJourneyInJourney();
$relation->setJourney($session->get('journey_id'));
$relation->setDocument($document->getId());
$em->persist($relation);
$em->flush();
}
$pdf=$this->generatePDF($form);
$pdf->Output('file.pdf', 'I');
return $this->redirect($this->generateUrl('another_site'));
}
}
return $this->render('Bundle:Page:document.html.twig');
}
public function generatePDF($form)
{
$pdf = $this->get("wrep.tcpdf")->create();
$pdf->SetTitle('Tittle');
$pdf->SetHeaderData('', 0, ' ', ' ', array(0,0,0), array(0,0,0));
$pdf->setHeaderFont(array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->SetPrintFooter(false);
$pdf->SetAutoPageBreak(TRUE);
$pdf->AddPage();
$html = $this->renderView('Bundle:document.twig',
array(
'traveller' => $form["name"]->getData().' '.$form["surname"]->getData(),
'document' => $form["full_name"]->getData()
)
);
$pdf->writeHTML($html, $ln=false, $fill=false, $reseth=false, $cell=false, $align='');
return $pdf;
}
}
그러나이 PDF로 생성되는 코드와 브라우저
그것을 다운로드하지만 페이지가 리디렉션되지 않습니다.
이 컨트롤러가있는 사이트에서 양식 및 버튼 'pdf 생성'버튼을 누르면 pdf 파일을 생성하고 파일을 다운로드 한 다음 예를 들어 홈 페이지로 리디렉션하게합니다. – paciks
사용자를 홈페이지로 리디렉션하십시오. 홈페이지에서 자바 스크립트를 추가하여 사용자를 pdf로 리디렉션하십시오. 사용자가 아직 홈페이지에 머무르는 동안 PDF 다운로드가 시작됩니다. – fkrauthan