Showing posts with label FPDF. Show all posts
Showing posts with label FPDF. Show all posts

Thursday, October 27, 2011

Netbean chinese character problem

Probably happen in my pc (Window XP Home)
Create a new .php file, then when I paste the chinese character it show all right

Problem rises when the display (like export into PDF)
This is because the character encoding for the netbeans (NetBeans IDE 6.9.1) is not UTF-8

So simply fix this problem by changing the file type. As for me, I'm using notepad2 to change to file type into UTF-8. Below is the example


http://localhost/search/

Thursday, January 20, 2011

PHP generate document PDF, ODT, Excel (XLS)

Just to record down any PHP library that can help in generate document

PDF
FPDF = http://www.fpdf.org/

ODT
odtPHP = http://www.odtphp.com/

XLS (Excel)
PHPExcel = http://phpexcel.codeplex.com/

odtPHP is from Anaska. Who / what is Anaska?
Not sure for myself but I do belive they produce something really useful. Check out your WAMP it is from Anaska too :D

Tuesday, December 14, 2010

FPDF - MutiCell - underline on each line

FPDF - MutiCell - underline on each line


Draw line under each line when new line is created when using FPDF. Or simply like picture below


Lazy to put picture


 


If you are using FPDF and want to make a line at the bottom of the text using Muticell, the parameter you send willl be like this


$pdf->MultiCell( 10, 100, "Hello World", 'B')


Where the 'B' represent line at bottom


 


But if you have a case like $pdf->MultiCell( 10, 100, "Hello \nWorld", 'B') //New line


or $pdf->MultiCell( 10, 100, "Hello World Hello World Hello World Hello World Hello World Hello World ", 'B') //Text too long auto new line


They will look like this


Lazy to put picture


 


And what you want is to look like this


Lazy to put picture


 


If you change the text into underline, it also does solve the purpose but it is not underline upon cell. It will be underline upon text


Lazy to put picture


 


So what left is only a tweak to the FPDF where I will tell you where to modify, which is in the function MultiCell(...) of course


First of all, I'm using FPDF version 1.53 (2004-12-31) where Olivier PLATHEY said "You may use and modify this software as you wish."


So this tweak is legal


Second, this code I write is free you may use and modify what I code as you wish. This is also 'AS IS', if anything happen dont blame me


If got bug, I dont care because with this code I already manage to get what I want


 


Lets start


 


Step 1


Go to the function MultiCell($w,$h,$txt,$border=0,$align='J',$fill=0)


 


Step 2


Inside there, you will see function Cell(...) is called 4 times and what you need to do is add additional code at the bottom of cell number 1 and 3


If I was correct


Cell no 1 is at line 755


Cell no 3 is at line 794


 


Step 3


Make the code to look like this. Make it like that at the 1st and 3rd cell



$this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill);

//Hassif. If you want the Multicell to have a bottom line at each text. use this
//Common border 'B' only bottom line at the end of text. Not at each line of text
if( strpos($border,'Z')){
$this->Line( $this->x, $this->y, $w+$this->x, $this->y);
}



 


Step 4


It done. So to use this feature you need to put $pdf->MultiCell( 10, 100, "Hello \nWorld", 'BZ') which is additional 'Z' character


 


Im kind of busy right now to explain further, so later...

Thursday, September 30, 2010

PHP ' become '

in PHP What happen when I output the string into text file is
The character ' become '

Copy this ' to create this '

' is a html character special code that represent ' symbol
Means it will display correctly as ' if you see it in web browser

Simply solving the problem by html_entity_decode( "'", ENT_QUOTES)

Note that html_entity_decode( "'") will not work
I found this solution in some page (didnt remember the site URL, sorry >.<)

So what is this html_entity_decode(...) function?
It is use to convert special html character into the normal character
Detail was in http://php.net/manual/en/function.html-entity-decode.php

The inverse of it was htmlentities(...)
Detail was in http://www.php.net/manual/en/function.htmlentities.php

Tuesday, August 31, 2010

FPDF °C become °C

Keyword
FPDF °C become °C
FPDF °C problem
FPDF symbol problem
FPDF degree celsius temperature problem

I having a bug when I create a file from FPDF the character when wrong.
The wrong is the symbol where °C become °C

I try to change the FPDF font into UTF-8 by embedding UTF-8 font into it but still problem (my database and html page display the °C correctly)

after several experimenting cause googling is failed (4 hours of stress)
the reaseon is because of my page encoding. FPDF write into the paper using 'ISO-8859-1' encoding.
Thus UTF-8 is °C and when it write it become ISO-8859-1 which is °C

So long for the chatting lets cut to the point

use utf8_decode("°C") will solve your problem. It will convert UTF-8 to ISO-8859-1

HOpe this help cause 'quick googling' disappoint me

Just for my own reference to converting string