How to Generate PDF from Mysql or ORACLE Database using PHP

Jyotishgher Astrology
By -
0

 

How to Generate PDF from Mysql Database using PHP


What is FPDF ?

  • FPDF is a PHP class library which allow us to generate PDF file using PHP.
  • In FPDF, ‘F’ stands for Free. So We can say FPDF  means Free PDF .
  • It is Open Source library. You may use it  and modify for any kind of usage to suit you needs.

Features  or Advantages of FPDF Library:

  • You can manage page format and margin.
  • Easily Header and Footer Management of PDF file.
  • Automatic Page Break
  • Line break and text justification automatically.
  • Image Support with format JPEG,JPG,PNG,GIF.
  • Links, Colors, True Type and encoding Support.
  • Page Compression

Step by Step Process to generate PDF using FPDF:

Step-1: Select the data from MySQL database into the page
Step-2: Download the FPDF library from fpdf.org 
Step-3: Upload FPDF file into your application Folder
Step-4: Include the fpdf.php file into your application file


How to Generate PDF from ORACLE Database using PHP

<?php

$conn = oci_connect('xxx', 'xxx', 'xxxxx');  // DIRECT INSERT

include_once('pdf/fpdf.php');


if (!$conn) {

    $e = oci_error();

    trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);

}

$EMPNO=$_REQUEST['EMP_NO'];


//$display_heading = array('PAY_ACCT_CD'=>'PAY_ACCT_CD', 'AMT_THIS_PRD'=> 'AMT_THIS_PRD');


$result = oci_parse($conn, "PUT HERE YOUR SQL QUERY") 

or die("database error:". oci_error($conn));

oci_execute($result);



$pdf = new FPDF(); 

$pdf->AddPage();


$width_cell=array(20,50,40,40,40);

$pdf->SetFont('Arial','B',16);


//Background color of header//

$pdf->SetFillColor(193,229,252);


// Header starts /// 

//First header column //

$pdf->Cell($width_cell[0],10,'Code',1,0,'C',true);

//Second header column//

$pdf->Cell($width_cell[1],10,'Name',1,0,'C',true);


//3rd header column//

$pdf->Cell($width_cell[1],10,'Amount',1,0,'C',true);


//// header ends ///////


$pdf->SetFont('Arial','',10);

//Background color of header//

$pdf->SetFillColor(235,236,236); 

//to give alternate background fill color to rows// 

$fill=false;



$i=0;

$pdf->Ln();

while($row = oci_fetch_assoc($result)) 

 {

$pdf->Cell($width_cell[0],10,$row['PAY_ACCT_CD'],1,0,'C',$fill);

$pdf->Cell($width_cell[1],10,$row['PAY_ACCT_NAME'],1,0,'L',$fill);

$pdf->Cell($width_cell[2],10,$row['AMT_THIS_PRD'],1,0,'L',$fill);

$pdf->Ln();

//to give alternate background fill  color to rows//

$fill = !$fill;

$i++;

}

/// end of records /// 

 

$pdf->Output();

?>


GO TO ANDROID STUDIO AND ON CLICK LISTNER ADD THIS CODE:


String imageurl = response.optString("PdfUrl");
                            DownloadManager dm = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
                            DownloadManager.Request request = new DownloadManager.Request(Uri.parse(imageurl));

                            request.allowScanningByMediaScanner();
                            request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); //Notify client once download is completed!


                            dm.enqueue(request);

Post a Comment

0Comments

Post a Comment (0)