-3

Hello All,

I have a form which have 5 step and in final step user click on submit than all data will store in db.

Now I want to generate pdf after 1st step, in my form 1st step have personal details fields. So in second step user can download these dynamic pdf have 1st step data. I know how to generate PDF, just want to do this with dynamic variables.

But here the question is i have no data to get from db these all fields store at the end of the all sep. How can i get the 1st step data to generate PDF file.

Thanks in advance !

Ajay Patel
  • 5,298
  • 11
  • 55
  • 87
  • 3
    May I suggest that you indicate what research you've carried out when asking questions? Readers on StackOverflow nearly always want to know what you've already tried. – halfer May 14 '12 at 10:15

5 Answers5

8

you can use FPDF classes. It is very simple to use, like in this example:

<?php
require('fpdf.php');

$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$pdf->Output();
?>
Eugene Mayevski 'Callback
  • 45,135
  • 8
  • 71
  • 121
Jayyrus
  • 12,961
  • 41
  • 132
  • 214
  • Please read question once , i know FPDF , i want to generate it dynamically – Ajay Patel May 14 '12 at 07:45
  • 4
    @AjayPatel - in my view this answer clearly comes from someone who _has_ read the question. Store your form values in session variables, and then use the features of FPDF to create your document. The 'Hello Word' above can come from a database, a session variable, direct user input - from anywhere, in fact. – halfer May 14 '12 at 10:13
  • @halfer I am asking that one, not how to generate pdf, I wrote in question simply that i know how to generate pdf – Ajay Patel May 14 '12 at 10:19
  • 1
    Here's how to store a value in a session: call `session_start();`, then use `$_SESSION['var'] = 'value';`. I'd recommend doing a web search around 'PHP sessions' - there are _thousands_ of pre-existing sources for this. – halfer May 14 '12 at 10:22
2

You can use session to store the data in the first step and then use one many libraries like TCPDF to generate pdf.

matino
  • 17,199
  • 8
  • 49
  • 58
  • Is it possible with AJAX req and any example link – Ajay Patel May 14 '12 at 07:48
  • Just make a php script that generates pdf based on the form data, call it using jquery ajax function when user clicks the button "next step". An exmaple of jquery ajax - http://stackoverflow.com/questions/5004233/jquery-ajax-post-request-for-an-example – matino May 14 '12 at 07:54
1

I think the TCPDF FLOSS PHP class may help you.

inevio
  • 837
  • 6
  • 12
sohaan
  • 261
  • 1
  • 4
  • 9
0

I think cookie is the best idea

<SCRIPT TYPE="text/javascript">
set_cookie( "name", "ajay", 1 );
set_cookie( "id", "101", 1 );
set_cookie( "gender", "male", 1 );


function set_cookie ( cookie_name, cookie_value,
    lifespan_in_days, valid_domain )
{
    // http://www.thesitewizard.com/javascripts/cookies.shtml
    var domain_string = valid_domain ?
                       ("; domain=" + valid_domain) : '' ;
    document.cookie = cookie_name +
                       "=" + encodeURIComponent( cookie_value ) +
                       "; max-age=" + 60 * 60 *
                       24 * lifespan_in_days +
                       "; path=/" + domain_string ;
}


</SCRIPT>

Now using FPDF

<?php
require('../fpdf.php');

$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');

$pdf->Cell(80,10,$_COOKIE['name']);
$pdf->Cell(80,10,$_COOKIE['id']);

$pdf->Output();
?>
Ajay Patel
  • 5,298
  • 11
  • 55
  • 87
  • That would work, but I'd not use JS for this, since it can be disabled by the user, and some (mobile) platforms don't use it. – halfer May 14 '12 at 10:47
  • @halfer ohh yes, what you suggest expect AJAX – Ajay Patel May 14 '12 at 10:50
  • If you are submitting the whole of your form to the server then there's no need to use AJAX - just do it in your `POST` handling section in PHP. You'd only need to use AJAX if you are submitting form values via AJAX anyway. – halfer May 14 '12 at 10:56
  • I wrote in question that i am storing data in last step, so its not the solution. – Ajay Patel May 14 '12 at 10:58
  • 1
    Ha `:)` - well your question was unclear (hence the downvotes). My understanding was that in each of your five stages, you'd submit the data to the server and store it in a session - however it now seems that after each of your stages, you are not sending anything to the server. How are you storing that information between stages? What is the transition between one stage and the next? Are you hiding one part of the form and revealing another, using JavaScript? Or is it all on a single page, and each stage is just a different section on the page? – halfer May 14 '12 at 11:04
  • @halfer Its single form dived in step open http://themes.vivantdesigns.com/?theme=vpad and click on wizard for ex – Ajay Patel May 14 '12 at 11:12
  • Right - a link/screenshot of that in the initial question might have clarified things substantially `;-)`. Yeah, use an AJAX operation after the first section - check their docs to see how to do this. – halfer May 14 '12 at 11:18
0

If you need to generate a sophisticated dynamical PDF document out of a Word or ODT template you may try Docxpresso

Eduardo Ramos
  • 416
  • 3
  • 8