0

Hi ppl,

I have a dynamic form, where user can add/remove rows and enter data. This form is basically a invoice. On clicking save button, the data should get saved into db, also a pdf file containing the details of the invoice should be generated.

I came across this

<?
require('html2fpdf.php');
$pdf=new HTML2FPDF();
$pdf->AddPage();
$fp = fopen("sample.html","r");
$strContent = fread($fp, filesize("sample.html"));
fclose($fp);
$pdf->WriteHTML($strContent);
$pdf->Output("sample.pdf");
echo "PDF file is generated successfully!";
?>

sample.html

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Nations and Flags</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<center><h3>Nations and Flags</h3></center>
<table border="1" width="500" cellspacing="0" cellpadding="2" align="center">
<tr><td>Australia</td><td width="200"><img src="as-t.jpg" width="48" height="32"></td></tr>
<tr><td>Canada</td><td width="200"><img src="ca-t.jpg" width="48" height="32"></td></tr>
<tr><td>China</td><td width="200"><img src="ch-t.jpg" width="48" height="32"></td></tr>
<tr><td>Deutschland - Germany</td><td width="200"><img src="de-t.jpg" width="48" height="32"></td></tr>
<tr><td>France</td><td width="200"><img src="fr-t.jpg" width="48" height="32"></td></tr>
<tr><td>India</td><td width="200"><img src="in-t.jpg" width="48" height="32"></td></tr>
<tr><td>United Kingdom</td><td width="200"><img src="uk-t.jpg" width="48" height="32"></td></tr>
<tr><td>United States of America</td><td width="200"><img src="us-t.jpg" width="48" height="32"></td></tr>
</table>
<body>
</body>
</html>

but here the html page is static, but i have a dynamic page, can anyone guide how to get around with this? or is there any other better method than this. since this is work related i cant use commercial pdflib.

thank you for ur time and suggestion.

Edited by puvi: n/a

3
Contributors
7
Replies
11
Views
6 Years
Discussion Span
Last Post by puvi
1

$strcontent (line 8) can be any html (including the html that you are creating dynamically). The html2pdf examples read example files as the input but there is no requirement to do it that way. In your code, as you create lines of output, append them to $strcontent until it has the full output ( $trcontent .= ...)

0

hey chrishea, thanks a ton for the reply, i have a doubt, instead of sample.html can i use sample.php because it contains the form to enter the details of the invoice, if its not possible to use sample.php then how do to get around with it..

thanks for ur time..

0

frens,

i played around with this code a lil, i could generate the pdf file. however, i could not get how to pass the user input entered in form to the pdf. lets say i have purchase_order.php when the user enters the details and clicks "generate pdf". all the user entered details shud be passed on to the page gen_pdf.php where i am generating the pdf, I already have a save button in purchase_order.php and i ve set the action to self. So i am thinking of using href link for "generate pdf" and appending the values which i need to display in the pdf file. But there i have lot of data to pass.

Is there any other alternative i can approach. please drop in any ideas/hints

any help most appreciated.
Thanks

0

the source code u r writing musr be within the code tag....
and bt the way i saw ur form it is missing submit button....
to do it simple....i m posting an example to do it....
the code for abc.php...

<form action="session.php" method="POST">
Enter ur name<input type="text" name="chk">
<input type="submit" value="submit" name="submit">
</form>

now code for session.php

<?php
echo $_POST['chk'];
?>

just take this as example and try to find error in ur code.....
and also post full code so that we can debug n find the error....

0

hey,

i have my code like this

code for abc.php

<form action="abc.php" method="POST">
Enter ur name<input type="text" name="chk">
<input type="submit" value="save" name="submit">
</form>

i ve written the code to save the user input into db in the same file. it works fine.
now to generate pdf, if i use another submit button for "Generate PDF", and continue to write the code in same file, it becomes difficult to maintain, so i want to keep it in different file like session.php, i cant use something like action=session.php right? cos i already have action=abc.php. so, i thought i cud make generate pdf a link and use href, but there are many user input values, which i need to display in the pdf. so i wanted to know if there are any alternative other than using href.

Also, i wanted some guidance on how to get the dialogue box asking to open the file or save the file, and user can choose to save the file to download to the system.

thanks for your time and suggestion.

Edited by puvi: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.