Hi frens,

I have already asked this question in another thread, but then felt this issue was irrelevent to that thread.

I have a requirement to generate a invoice in pdf format and download it.

i have a dynamic form, where user can enter date, choose option from dropdown, add/remove rows depending upon no. of products.

code in abc.php

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

i ve written the code to save the user input into db in the same file. it works fine.

to generate pdf, i looked around in internet and found pdflib lite, r&os, fpdf to generate pdf, i decided to use fpdf(hoping that this has good support from its makers),i generated some pdfs to understand how it works and its working fine.

now to generate the invoice, i wrote something like this in abc.php

codes to save the user input values to db(this works fine)
class PDF extends FPDF
//some functions
$pdf=new PDF();
//more pdf codes
if($result == true)

echo "<script>window.location.href=xyz</script>";	



if i run this pdf separately in genratepdf.php it runs fine, however i have lots of user input to display in the pdf, and i could not figure out how to pass the values to different file, cos i already have a submit button and action=abc.php,so i wrote it in the same abc.php file and this doesnt generate pdf.

so my doubts are is it ok to redirect the page after "$pdf->Output();" ??

if not, will i have to keep this code in different file?? then how do i pass all the user input values(minimum 15- max depends on the no. of products)to that file?? i dont think using href is a good option, at the same time i dont know any other alternative.:@

please suggest some alternative for this..

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.

$pdf->Output() writes a PDF file. This cannot contain JavaScript. The browser will not understand your code.
For passing variables between scripts use sessions and the $_SESSION array.

add one more parameter to following function call



hey smantscheff and urtrivedi thanks for your replies.

i had a doubt abt _session though. will all the user entered data be in session automatically(like _POST) or do i have to explicitly assign to the session before passing it?



Any how You must set and use session variables there is no link between post and session.


if($validuser) //check login details if valid then set session variables
   $_SESSION['username']=$loggeduser;//logged user may be userid, email or whatever you like to set.


if(!$_SESSION['on'])  //if user not logged then send to login page

echo "welcome {$_SESSION['username']}";

hey urtrivedi, i agree, my 1st question was not concerning session, sorry for that, anyways thanks for the help.

i did something like this

<form method="post" action="abc.php">
First name: <input type="text" name="firstname" id="fname" /><br />
Last name: <input type="text" name="lastname" id="lname" />
<input type="submit" name="submit" value="save"/>
$fname = $_POST['fname'];
$lname = $_POST['lname'];

$_SESSION['fname'] = $_POST['fname'];
$_SESSION['lname'] = $_POST['lname'];

//code to save the data into db


in generatepdf.php, i am using $_SESSION to display the user input.
but when i run this abc.php i get this error

"Warning: require(../fpdf.php) [function.require]: failed to open stream: No such file or directory in /mnt/opt/lampp/htdocs/GEMS/web/generatepdf.php on line 4"

but i have kept all the required files like fpdf.php makefont.php in the same folder as the generatepdf.php

can anyone help me to get this straight.

is it because i am using header to redirect to generatepdf.php?? why is this happening i wud like to know..

You must also use session_start() in your generatepdf.php before using session variable. (this is not something causing problem, it is addtional hint)

Now I never merge all folders in one following is my directory structure


so when I refer fpdf in my generatepdf.php, i will write


Diretory structure is attached

Check how your files are stored

thanks a ton urtrivedi, now that error is gone but i got another one grrrrr....


"Warning: fopen(../images/gemsheader.png) [function.fopen]: failed to open stream: No such file or directory in /xyz/fpdf/fpdf.php on line 1226
FPDF error: Can't open image file: ../images/gemsheader.png"

i ve kept the gemsheader.png in /xyz/web/images
generatepdf.php is in /xyz/web

in generatepdf.php i ve written like this

function Header()
	//Arial bold 15
	//Move to the right
	//Line break

what could be the issue here...phew..i ve been stuck with this issue since morning..


Your image directory structure must be like attached file

forget my preovis post

give only single dot instead of double dot



all thanks to you i got to see the output, before the end of todays working hours...
what a relief..

thank you sooo much..

@Laura if you want to be helped then open a new thread, explain the problem and attach the relevant code. Bye!

Sorry Sir. But I think nothing wrong with the code. But, it cant be export to pdf using fpdf. I dont know where to start explain. Here is the code, first is ultrasonictr.php and the second is pdf.php.

<form action="merging.php" name="visultra" method="POST">
<script type="text/javascript">
$(function ()  
   var dataSource = [
 //data ini ambil dari rata2/average ny yang dari yg ultrasonic.php
    { thick: "Average Thickness 10-20 Below Surface", prec1: <?php echo $has->av1 ?>},
    { thick: "Average Thickness Above Surface Level", prec2: <?php echo $has->av2 ?> },
    { thick: "Average Thickness 10-20 Above Surface", prec3: <?php echo $has->av3 ?> },
    { thick: "Average Thickness 50-100 Above Surface Level", prec4: <?php echo $has->av4 ?> },
    { thick: "Average Thickness 150-200 Above Surface Level", prec5: <?php echo $has->av5 ?> }
    dataSource: dataSource,
        argumentField: "thick"
    panes: [{
            name: "firstPane"
    series: [{ 
            type: "bar",
            valueField: "prec1",
            name: "Numb1",
            label: {
                visible: true,
                customizeText: function (){
                    return this.valueText  + " mm";
            type: "bar", 
            valueField: "prec2",
            name: "Numb2",
            label: {
                visible: true,
                customizeText: function (){
                    return this.valueText + " mm";
        }, {
            type: "bar",
            valueField: "prec3",
            name: "Numb3",
            label: {
                visible: true,
                customizeText: function (){
                    return this.valueText  + " mm";
        }, {
            type: "bar",
            valueField: "prec4",
            name: "Numb4",
            label: {
                visible: true,
                customizeText: function (){
                    return this.valueText  + " mm";
        }, {
            type: "bar",
            valueField: "prec5",
            name: "Numb5",
            label: {
                visible: true,
                customizeText: function (){
                    return this.valueText  + " mm";
    valueAxis: [{
        pane: "firsPane",
        grid: {
            visible: true
        title: {
            text: "Thickness Result, mm"
    legend: {
        verticalAlignment: "bottom",
        horizontalAlignment: "center"
        <div class="line"></div>      
        <div class="title">
            <h1>Charts</h1>&nbsp;&nbsp;&nbsp;<h2>Ultrasonic Thickness</h2>
        <div class="content">
            <div class="pane">
                <div class="long-title"><h3></h3></div>
                <div id="chartContainer" style="width: 100%; height: 440px;"></div>
                <div class="credits">Dimensi Barumas Perdana</div>

<table border=1 width="30%">
    <th>Average 1</th>
    <th>Average 2</th>
    <th>Average 3</th>
    <th>Average 4</th>
    <th>Average 5</th>
        <td><center><b><?php echo $has->av1?></b></center></td>
        <td><center><b><?php echo $has->av2?></b><center></td>
        <td><center><b><?php echo $has->av3?></b><center></td>
        <td><center><b><?php echo $has->av4?></b><center></td>
        <td><center><b><?php echo $has->av5?></b><center></td>
        <td><center><b><?php echo $has->cat?></b><center></td>
        <td><center><b><?php echo $has->remark?></b><center></td>
<table border=1 width="30%">
    <tr><td><center><input type="submit" name="merging" value="Merging"></center></td></tr>

<!-- this is pdf.php-->
$mysqli = new mysqli('localhost', 'root', '1234', 'dbparea');
if ($mysqli->connect_error) {
    die('Connect Error (' . $mysqli->connect_errno . ') '
            . $mysqli->connect_error);


class PDF extends FPDF {
function Header() {
    $this->Cell(19,1,'Data Komentar',1,0,'C');

function Footer() {
    $this->Cell(0,1,'Halaman '.$this->PageNo().'/{nb}',0,0,'C');

$pdf=new PDF('P','cm','A4');
$pdf->Write(1,'Oleh: ');

When I click "SAVE", it call pdf.php and built a doc into pdf. But, it displayed : "Failed to load PDF Document". I dont know what wrong.
Thanks for the help. God bless you.