PdfBundle icon indicating copy to clipboard operation
PdfBundle copied to clipboard

Not render pdf template

Open freenando opened this issue 13 years ago • 5 comments

Hello, I need some help to generate a pdf with your bundle. I think installation was correctly and now I am trying to generate a pdf document like this:

//Controller in my bundle public function pdfAction($id_escuela, Request $request) { $format = $this->get('request')->get('_format'); return $this->render(sprintf('BackendAlumnosBundle:Default:pdfAlumnos.pdf.twig', $format)); }

//pdfAlumnos.pdf.twig


<pdf>
    <dynamic-page>
        Hello FER
    </dynamic-page>
</pdf>

But it shows in the browser as html page with this source code <pdf> <dynamic-page> Hello FER </dynamic-page> </pdf> What I am doing wrong? Why could be the template isn´t rendered?

Thanks for your work!

freenando avatar Feb 20 '13 09:02 freenando

Are you sure the format of the request (_format attribute) is pdf format? It looks like it isn't.

psliwa avatar Feb 20 '13 22:02 psliwa

I have the same issue. I am not getting a format in the request as I will always want to generate a pdf when calling this controller. Here is my code:

/**

  • @Pdf() */
    public function generatePdfAction() { return $this->render(sprintf('MyFreelancerPortfolioBundle:Main:demopdf.%s.twig', 'pdf'), array( 'content' => '

    Testing PDF

    ', )); }

Magnanimity avatar Oct 11 '13 10:10 Magnanimity

Please use

code notation

so I don't get notified :wink:

pdf avatar Oct 11 '13 12:10 pdf

@Magnanimity : you should set default request format to "pdf" in your route definition.

..
@Route("/some", defaults={ "_format"="pdf" })
..

psliwa avatar Oct 11 '13 12:10 psliwa

And how to set it outside of an controller?

Reason is I want to generate a invoice which isn't send to the browser, but instead sent as an email to the customer.

Dorwido avatar Jun 30 '15 14:06 Dorwido