ScoRpion
ScoRpion

Reputation: 11474

How can i generate pdf reports using symfony2?

I have created an examanition module which provides the report card to the user as an HTML (twig) format. Now I want the user should be able to save the report card as pdf. I have added a button as Save ReportCard and I want to write the code in my controller to generate this pdf file with same content as of the html. I googled and found these links:

  1. PDF Lib 8
  2. Generate PDFs with PHP

These links where great but I couldnt get how can i use them in symfony2. I am new to symfony2 and Php. Can anyonw help me here with the same.

Upvotes: 4

Views: 21258

Answers (3)

Jovan Perovic
Jovan Perovic

Reputation: 20201

I have spent many hours in search for appropriate library. The primary goal was to generate PDF as easily as possible without coordinate positioning, special functions for line-feed and what not...

The best match I found so far was: https://github.com/psliwa/PdfBundle

... which has Symfony bundle and GitHub entry contains tons of examples. Excellent library.

Upvotes: 4

Flask
Flask

Reputation: 4996

Another solution, which is more painless than create a whole custom PDF, would be to create a print css. then get the whole DOM with a lib like wkhtml2pdf. There is also a Lib from knplabs https://github.com/KnpLabs/snappy and the bundle https://github.com/KnpLabs/KnpSnappyBundle

i often use this for tricky html5 projects. with the javascript support from wkhtml2pdf you can add svg's and other pretty things to your pdf...

Upvotes: 14

smoreno
smoreno

Reputation: 3550

A great library with a lot of features is TCPDF. WhiteOctoberTCPDFBundle or IoTcpdfBundle are some bundles created by community based in that library. You can find some bundles that help you to create PDFs at knpbundles.

Upvotes: 6

Related Questions