/    Sign up×
Community /Pin to ProfileBookmark

Problem in using FPDF extension

Hello everyone, I want to use the fpdf extension in my project to fetch the data from database table. but I am confused in its layout that How to style its layout.

I want that the data should be displayed in this format.

[B]Name[/B] [B]Email[/B] [B]Amount[/B] [B]Comments[/B]
[I]john[/I] [I][email protected][/I] [I]12[/I] [I]test comments[/I] etc etc

so how can I style my data in this format thanks in advance.

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@ginerjmNov 18.2014 — 1 - One does not use the FPDF extension to "fetch the data from database table".

2 - You still have to do all the work to get your data from your db.

Once you have a script that does what you want, you then use FPDF to output that data. You have to design the layout of the "page" yourself and then use the FPDF functions to create that page starting with the page size and orientation, fonts and font sizes. Then you use the Cell our MutliCell functions to output your data fields in the columns and rows/lines that you have designed. Kind of like designing an html table but you use different FPDF functions instead of tags to build the output.

I highly suggest setting some vars to hold the widths of each column in your layout and then use those vars in the calls to Cell or MultiCell. That way adjustments are easy to make. Same for the line height value that you need to set.
Copy linkTweet thisAlerts:
@NogDogNov 18.2014 — IIRC, FPDF can take HTML as the input and output it as PDF. If that's the case, you could first create HTML output that looks the way you want, then instead of outputting it, send it to FPDF instead.
Copy linkTweet thisAlerts:
@ginerjmNov 18.2014 — That would be a much improved version over the one I've been using.
Copy linkTweet thisAlerts:
@NogDogNov 18.2014 — That would be a much improved version over the one I've been using.[/QUOTE]

Maybe it was TCPDF? (It was several years ago. ? )

PS: I hate PDF about as much as I hate SOAP. ?
Copy linkTweet thisAlerts:
@Naveed_MarwatauthorNov 19.2014 — here is the required design image that I want to set and http://postimg.org/image/e7zor5il5/

and below is the required code to fetch the data from database.

<i>
</i>&lt;?php
require("fpdf/fpdf.php");

<i> </i>/* Fetch the data from the database. */
<i> </i>require("database.php"); // connection to the database

<i> </i>$expenses = new FPDF();
<i> </i>$expenses-&gt;AddPage();
<i> </i>$expenses-&gt;SetFont('Arial', 'B', '16');
<i> </i>$expenses-&gt;Cell(0, 10, 'Account Management System', 1, 1, 'C');

<i> </i>$expenses-&gt;SetFont('Arial', 'U', '12');
<i> </i>$expenses-&gt;Cell(0, 10, 'Expenses Reports', 1, 1, 'C');
<i> </i>$expenses-&gt;Ln();

<i> </i>$expenses-&gt;SetFont('Arial', 'B', '10');
<i> </i>$expenses-&gt;Cell(30, 10, 'Date', 1, 1);
<i> </i>$expenses-&gt;Cell(30, 10, 'Amount', 1, 1);
<i> </i>$expenses-&gt;Cell(30, 10, 'Description', 1, 1);
<i> </i>$expenses-&gt;Cell(30, 10, 'Comments', 1, 1);
<i> </i>$expenses-&gt;Ln();
<i> </i>$qry = " SELECT * FROM expenses ORDER BY date ";
<i> </i>$result = mysql_query($qry) or die(mysql_error());
<i> </i> while ( $row = mysql_fetch_array($result) )
<i> </i> {
<i> </i> $date1 = $row['date'];
<i> </i> $amount1 = $row['amount'];
<i> </i> $description1 = $row['description'];
<i> </i> $comments1 = $row['comments'];

<i> </i>$expenses-&gt;Cell(60, 10, $date1, 0, 1, 'R');

<i> </i>$expenses-&gt;Cell(60, 10, $amount1, 0, 1, 'R');

<i> </i>$expenses-&gt;Cell(100, 10, $description1, 0, 1, 'R');

<i> </i>$expenses-&gt;Cell(100, 10, $comments1, 0, 1, 'R');
<i> </i>}
<i> </i>$expenses-&gt;Output();

?&gt;

http://postimg.org/image/e7zor5il5/
Copy linkTweet thisAlerts:
@Naveed_MarwatauthorNov 19.2014 — I am using this extension http://www.fpdf.org/

if anyone have better idea then please share with me.
Copy linkTweet thisAlerts:
@ginerjmNov 19.2014 — I think you have the idea. Altho - some programming tips:

1 - Why start the pdf output before you have confirmed that your query runs successfully?

2 - keep all your output operations together. For ex.


a - run your query and confirm it succeeded

b - Now start your pdf and output your headings using the fpdf header function - not the way you did it. (What will happen if your report goes to a second page?)

c - use your loop (as you are) to output each report line from each row

d - Then close the pdf.

Be sure you have covered all the arguments for each function call. IIRC you seem to be missing a couple but perhaps not. I'm sure you will have to do some tweaking as you go to get it arranged the way you want.

Good luck and don't be afraid to post with more questions.
×

Success!

Help @Naveed_Marwat spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...