How to create pdf like a example using fpdf

12,755

Solution 1

I have tried fpdf and a few other libraries for a big job i have done a couple of years back. You might want to look at dompdf, the library takes html and converts it into pdf flawlessly (after a couple of tries to get it right, but still) - only thing is, read the docs - images (like your barcode there) must be linked with server path, i.e. /path/to/image/image.jpg

Solution 2

Basically it looks ok. Its just a bunch of little things to adapt. e.g. setting the font to bold is done via $pdf->SetFont('Arial','B',14); before the output statement and setting it back to $pdf->SetFont('Arial','',14); afterwards. See fpdf documentation for details.

Solution 3

Not overly familiar with fPDF. It looks OK for quick, simple stuff. Have you tried using R&OS ezPDF Creator instead - not sure what state of development/maintenance it's in these days but I think it may give you more detailed control for the kind of output you want. I've used it for years for bespoke PDF output from PHP. Just checked and it looks like it's still being maintained - see:

http://sourceforge.net/projects/pdf-php/

Cheers, Arthur

Share:
12,755
MD. ABDUL Halim
Author by

MD. ABDUL Halim

Updated on June 17, 2022

Comments

  • MD. ABDUL Halim
    MD. ABDUL Halim almost 2 years

    This is my PDF code below:

    $this->SetFillColor(0);
    $this->SetTextColor(255,255,255);
    $this->Cell(90,10,$airline_name,'LRBT',0,'L',true);
    
    $this->Cell('10',10,'','',0,'L',false);
    
    $this->SetFillColor(255,255,255);
    $this->SetTextColor(0);
    $this->SetFont('Times','',10);
    
    $this->MultiCell(90,5,$com_info,1,'L',false);
    
    $this->Ln(0);
    
    $this->SetY(23);
    $this->Cell(30,10,"MAWB",'LTB',0,'L',false);
    $this->Cell(60,10,$mawb,'TRB',0,'L',false);
    $this->Cell(10,10,'','',0,'L',false);
    
    $this->Cell(45,20,'This Pieces No.\n$pn','LR',0,'L',false);
    $this->Cell(45,20,'Total Pieces\n$pn','R',0,'L',false);
    $this->ln(0);
    
    $this->SetY(36);
    $this->Cell(30,10,"Booking_ref",'LTB',0,'L',false);
    $this->Cell(60,10,$booking_ref,'TRB',0,'L',false);
    $this->Cell(10,10,'','',0,'L',false);
    
    $this->Cell(25,20,'HAWB','LTR',0,'L',false);
    $this->Cell(65,20,$quotation_no,'TR',0,'L',false);
    

    According to above code, the PDF is as shown below: pdf image No.01 enter image description here

    Basically, I want to do display it as shown here: pdf image No.02 enter image description here

    In the PDF, the data will come from the database.

    I would like to display like pdf image No.02 But i have done like pdf image No.01.

    How to get the pdf image like pdf image No.02.

    How can I solve it? Please help.

  • Hafenkranich
    Hafenkranich almost 8 years
    generating html and convert it to a pdf is a last-resort workaround.
  • ied3vil
    ied3vil almost 8 years
    snapping a quick html for your desired layout is always easier, faster, and more convenient than 1000 lines of $this->SetXXXColor(); and $this->Cell(); and similar
  • Hafenkranich
    Hafenkranich almost 8 years
    agree, it's faster – but way less failprove to my experience. And the size of the PDF is most of the time relevantly bigger.
  • ied3vil
    ied3vil almost 8 years
    the size (file size) depends on more than one factor. plus, you got a bit of extra flexibility with html converted pdf's. That's what i used and it still works today, 5 years from when i implemented it...