Skip to content

Instantly share code, notes, and snippets.

@Vivek-abstract
Created December 31, 2018 08:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Vivek-abstract/c2af56e44f94039ec98f105613640ce9 to your computer and use it in GitHub Desktop.
Save Vivek-abstract/c2af56e44f94039ec98f105613640ce9 to your computer and use it in GitHub Desktop.
FPDF Usage in PHP
<?php
require 'fpdf/fpdf.php';
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial', 'B', 13);
// Here's how to display the POST parameters you passed from HTML
$pdf->Cell(0, 0, "Form: " . $_POST['name']);
// Rest of the file is just for ref, won't work on your PC, do look at last line however
$pdf->Image("img/ieeelogo.png", 60, 0, 80, 40, 'PNG');
$pdf->Image("images/" . $_SESSION['u_pic'], 160, 5, 35, 45);
$pdf->Rect(160, 5, 35, 45);
$pdf->Image("img/ieeelogo.png", 60, 140, 80, 40, 'PNG');
$pdf->Image("images/" . $_SESSION['u_pic'], 160, 145, 35, 45);
$pdf->Rect(160, 145, 35, 45);
$pdf->Ln(25);
$pdf->Cell(0, 10, "Date: " . date("d/m/Y"), 0, 1);
$pdf->Cell(0, 10, "New Membership (Student's Copy)", 0, 1, 'C');
$pdf->Cell(0, 10, "Name: " . $_SESSION['u_first'] . " " . $_SESSION['u_father'] . " " . $_SESSION['u_last'], 1, 1);
$pdf->Cell(90, 10, "Class: " . $_SESSION['u_class'] . "-" . $_SESSION['u_division'], 1, 0);
$pdf->Cell(0, 10, "Roll no: " . $_SESSION['u_rollno'], 1, 1);
$pdf->Cell(90, 10, "Reg no: " . $_SESSION['u_regno'], 1, 0);
$pdf->Cell(0, 10, "Year of Passing.: " . $_SESSION['u_yearofpassing'], 1, 1);
$pdf->Cell(0, 10, "Email ID: " . $_SESSION['u_email'], 1, 1);
$pdf->Cell(0, 10, "Phone no: " . $_SESSION['u_contact'], 1, 1);
$pdf->Cell(0, 20, "Address: " . $_SESSION['u_address'], 1, 1);
$pdf->Cell(90, 10, "Paid by: ", 1, 0);
$pdf->Image("images/" . $_SESSION['u_sign'], 30, 126, 40, 8);
$pdf->Cell(0, 10, "Recieved by: ", 1, 1);
$pdf->Ln(3);
$pdf->Cell(0, 10, "---------------------------------------------------------------------------------------------------------------------------- ", 0, 1);
$pdf->Cell(0, 10, "Form: " . $_SESSION['name']);
$pdf->Ln(28);
$pdf->Cell(0, 10, "Date: " . date("d/m/Y"), 0, 1);
$pdf->Cell(0, 10, "New Membership (Office Copy)", 0, 1, 'C');
$pdf->Cell(0, 10, "Name: " . $_SESSION['u_first'] . " " . $_SESSION['u_father'] . " " . $_SESSION['u_last'], 1, 1);
$pdf->Cell(90, 10, "Class: " . $_SESSION['u_class'] . "-" . $_SESSION['u_division'], 1, 0);
$pdf->Cell(0, 10, "Roll no: " . $_SESSION['u_rollno'], 1, 1);
$pdf->Cell(90, 10, "Reg no: " . $_SESSION['u_regno'], 1, 0);
$pdf->Cell(0, 10, "Year of Passing.: " . $_SESSION['u_yearofpassing'], 1, 1);
$pdf->Cell(0, 10, "Email ID: " . $_SESSION['u_email'], 1, 1);
$pdf->Cell(0, 10, "Phone no: " . $_SESSION['u_contact'], 1, 1);
$pdf->Cell(0, 20, "Address: " . $_SESSION['u_address'], 1, 1);
$pdf->Cell(90, 10, "Paid by: ", 1, 0);
$pdf->Image("images/" . $_SESSION['u_sign'], 30, 267, 40, 8);
$pdf->Cell(0, 10, "Recieved by: ", 1, 1);
// To show the PDF as output
$pdf->Output();
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<form action="generate_receipt.php" method="post">
<input type="text" name="name">
<button type="submit">Submit</button>
</form>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment