San Francisco - Linux certainly has established itself as a prominent server OS these days, pushing Unix into the background. But the open source OS shares the stage with commercial software giant Microsoft, which remains a dominant player with Windows Server.
Gartner research published this month found the server OS market shaping up as a battle between Windows Server and Linux. Gartner in other research also has found both OSes on a growth track in terms of revenue. "There still seems to be plenty of robust interest in deploying on Windows, but Linux is still very key," says Gartner analyst George Weiss.
[ The InfoWorld Test Center rates Windows Server 2008. | Why Linux is greener than Windows Server. | Has Linux killed OpenSolaris? ]
A lot of Linux usage is in Web server applications, but it's become increasingly common in mission-critical applications, Weiss notes. But "I don't have an indicator that says Linux is chewing up the market for Windows," he adds.
Other forms of Unix continue to fade away in what is becoming a two-OS choice for IT. "The key here is that really Linux and Windows are moving away from the pack here and it's becoming a two-horse race," says Jim Zemlin, executive director of the Linux Foundation.
Both Linux and Windows Server see datacenter growth
Regarding migration of current workloads, 43 percent of respondents in a Gartner survey at a Linux-oriented conference anticipated migrating mostly from Unix to Linux, 13 percent said they would migrate mostly from Windows to Linux, and only 4 percent said they would switch off Linux to go to Windows. Twenty-one percent had no plans to migrate workloads.
Gartner expects IT organizations to shift their focus to more-complex Linux deployments and continue a trend of migration from Unix. Gartner found that 52 percent of respondents anticipate that the total workload of their Linux server environment will increase moderately in 2008; another 25 percent said there would be a substantial increase. Only 5 percent anticipated moderate decrease, while 4 percent expected a substantial decrease in Linux workloads for this year. Respondents were three times more likely to migrate workloads from Unix to Linux than from Windows to Linux.
Although Linux growth is strong, so is that of Windows Server, according to Gartner's research. Linux was ranked by 39 percent of respondents as the OS expected to have the most growth in their datacenters during the next five years. Windows was a close second, ranked as the OS with the most growth potential by 35 percent of respondents at the Linux-oriented conference.
Based on Gartner's annual estimates for worldwide server shipment revenues, both Windows Server and Linux will increase. Windows Server sales will move from about $20 billion last year to roughly $22 billion in 2012; Linux will grow from about $9 billion last year to $12 billion in three years. But because Linux is often provided at no cost (with vendors making revenues from support contracts and other services), those numbers may not be comparable.
Roy Schestowitz, an ardent supporter of Linux and ardent opponent of Microsoft who runs the Boycott Novell Web site, argues that Linux gets shortchanged in surveys on market share because only "sold" OSes are counted -- and often just those sold as part of server hardware by major companies such as Dell Computer, Hewlett-Packard, and IBM.
Is it really a race?
With both OSes growing, should IT be thinking of Linux and Windows Server as either/or propositions? No.
Linux provider Red Hat sees heterogeneity ruling the day, with users deploying both Linux and Windows Server. Linux already has a large base in Web deployments but is expected to move into high-end database and enterprise application deployments, says Nick Carr, Red Hat's marketing director. Windows, meanwhile, has a large base as a server for Exchange Server, SQL Server, and file and print deployments, he notes.
"Nobody has a sort of homogeneous world anymore," Carr notes. "People tend to think that one grows at the expense of the other but that's not what's happening at the moment." That's why Red Hat and Microsoft recently agreed to let Red Hat Linux users run Windows servers in virtual machines and let Windows Server users run Red Hat Linux in VMs. "Increasingly, such servers that run in mixed environments rely on virtualization," notes Linux proponent Schestowitz.
CRIS Camera Services is an example of the mixed Linux-Windows Server environment that will keep both OSes in demand. At CRIS, Linux gets the nod for running PHP, MySQL, and Apache software, says Josh Treadwell, the company's IT director. But it relies on Windows Server for its Microsoft Dynamics and SharePoint applications. And its use of Windows Server benefits from the wide availability of Windows training certifications. "We have found college education circles around Microsoft languages," he says, noting there is no central certification for Linux.
The cost question
Possible reasons for moving to Linux include antipathy toward Microsoft and the perception that Linux is cheaper in terms of license fees, says Gartner's Weiss. Linux has an inside track with startups as well as with larger ventures such as Google, he notes -- two environments where cost or "anyone but Microsoft" concerns are key.
But the Linux financial advantage may not be real, Weiss says. When adding up the numbers for Linux deployments in a larger scalable environment, he does not see much difference among Linux, Unix, and Windows once you factor in the costs to achieve high availability, implement a global file system, and get technical support. Also, equipment expenses are a wash between Linux and Windows, he says: "Windows and Linux can run on the same hardware."
The Linux Foundation's Zemlin argues that Linux is in fact cheaper to use than Windows. One reason is the lack of licensing costs for Linux. Another is that Linux runs across a much wider variety of systems than the predominantly Intel x86-based Windows platform, he says, so you get an economy of scale across a mix of hardware. In addition to x86 serves and blades, both of which run Windows, Zemlin notes that Linux runs on mainframes, IBM Power systems, and other Unix-oriented hardware. "Linux can be a very cost-effective common denominator among these systems, he contends.
Some organizations may see cost savings from running free, unsupported Linux distros, but Gartner's Weiss says that is foolishly dangerous. A major outage or security breach without immediate access to a Linux support provider can easily wipe out any money saved from relying only on yourself. (Windows Server support is also needed, and it too requires paying a support provider.)
[source]
Showing posts with label more. Show all posts
Showing posts with label more. Show all posts
Thursday, March 19, 2009
Thursday, February 12, 2009
Email address validation using Javascript
In forms when using email ID fields it is a good idea to use client side validation along with your programming language validation. The following example shows how you can validate an email address for a form. The script is cross browser compatibe (works for all browsers).
<script language = "Javascript">
/**
* DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
*/
function echeck(str) {
var at="@"
var dot="."
var lat=str.indexOf(at)
var lstr=str.length
var ldot=str.indexOf(dot)
if (str.indexOf(at)==-1){
alert("Invalid E-mail ID")
return false
}
if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
alert("Invalid E-mail ID")
return false
}
if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
alert("Invalid E-mail ID")
return false
}
if (str.indexOf(at,(lat+1))!=-1){
alert("Invalid E-mail ID")
return false
}
if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
alert("Invalid E-mail ID")
return false
}
if (str.indexOf(dot,(lat+2))==-1){
alert("Invalid E-mail ID")
return false
}
if (str.indexOf(" ")!=-1){
alert("Invalid E-mail ID")
return false
}
return true
}
function ValidateForm(){
var emailID=document.frmSample.txtEmail
if ((emailID.value==null)||(emailID.value=="")){
alert("Please Enter your Email ID")
emailID.focus()
return false
}
if (echeck(emailID.value)==false){
emailID.value=""
emailID.focus()
return false
}
return true
}
</script>
<form name="frmSample" method="post" action="#" onSubmit="return ValidateForm()">
<p>Enter an Email Address :<input type="text" name="txtEmail"></p>
<p><input type="submit" name="Submit" value="Submit"></p>
</form>
source
<script language = "Javascript">
/**
* DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
*/
function echeck(str) {
var at="@"
var dot="."
var lat=str.indexOf(at)
var lstr=str.length
var ldot=str.indexOf(dot)
if (str.indexOf(at)==-1){
alert("Invalid E-mail ID")
return false
}
if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
alert("Invalid E-mail ID")
return false
}
if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
alert("Invalid E-mail ID")
return false
}
if (str.indexOf(at,(lat+1))!=-1){
alert("Invalid E-mail ID")
return false
}
if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
alert("Invalid E-mail ID")
return false
}
if (str.indexOf(dot,(lat+2))==-1){
alert("Invalid E-mail ID")
return false
}
if (str.indexOf(" ")!=-1){
alert("Invalid E-mail ID")
return false
}
return true
}
function ValidateForm(){
var emailID=document.frmSample.txtEmail
if ((emailID.value==null)||(emailID.value=="")){
alert("Please Enter your Email ID")
emailID.focus()
return false
}
if (echeck(emailID.value)==false){
emailID.value=""
emailID.focus()
return false
}
return true
}
</script>
<form name="frmSample" method="post" action="#" onSubmit="return ValidateForm()">
<p>Enter an Email Address :<input type="text" name="txtEmail"></p>
<p><input type="submit" name="Submit" value="Submit"></p>
</form>
source
PHPMailer: SMTP Authentication
Most of the hosting providers today disable anonymous user on their server or do not allow to send mail through script without SMTP authentication to stop the spamming from their servers. In such cases, you have to use SMTP authentication to send mail through PHP, ASP, or ASP.Net script. Below is the sample SMTP authentication script to send mail through PHP script using PHPMailer:
<?php
require("class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // send via SMTP
$mail->Host = "smtp.domain.com"; // SMTP servers
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "email@domain.com"; // SMTP username
$mail->Password = "password"; // SMTP password
$mail->From = "email@domain.com";
$mail->FromName = "Name";
$mail->AddAddress("Recipient@emailaddress.com","Name");
$mail->AddReplyTo("yourname@domain.com","Your Name");
$mail->WordWrap = 50; // set word wrap
$mail->IsHTML(true); // send as HTML
$mail->Subject = "Here is the subject";
$mail->Body = "This is the HTML body";
$mail->AltBody = "This is the text-only body";
if(!$mail->Send())
{
echo "Message was not sent";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
echo "Message has been sent";
?>
<?php
require("class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // send via SMTP
$mail->Host = "smtp.domain.com"; // SMTP servers
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "email@domain.com"; // SMTP username
$mail->Password = "password"; // SMTP password
$mail->From = "email@domain.com";
$mail->FromName = "Name";
$mail->AddAddress("Recipient@emailaddress.com","Name");
$mail->AddReplyTo("yourname@domain.com","Your Name");
$mail->WordWrap = 50; // set word wrap
$mail->IsHTML(true); // send as HTML
$mail->Subject = "Here is the subject";
$mail->Body = "This is the HTML body";
$mail->AltBody = "This is the text-only body";
if(!$mail->Send())
{
echo "Message was not sent";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
echo "Message has been sent";
?>
For more info about the PHPMailer Class, visit phpmailer.codeworxtech.com
Monday, January 12, 2009
Creating PDF using PHP
Portable Document Format (PDF) is an open file format created and controlled by Adobe Systems.
PDF files are very useful for data reporting. bcoz now every system having a pdf file reader.
The PDF functions in PHP can create PDF files using the PDFlib library created by Thomas Merz.
All of the functions in PDFlib and the PHP module have identical function names and parameters.
Using HTML2PDF we can convert html page to pdf.
HTML2PDF is a simple HTML to PDF tool which can quickly and easily convert thousands of HTML pages into PDF reports.
HTML2PDF (include PDFcamp + DocConverter COM) is the easiest way to convert your web pages and DOC, RTF, TXT, PPT, XLS files into PDF documents, HTML2PDF quickly and accurately transforms well-formed HTML, DOC, RTF, TXT, PPT, XLS files into PDF files, the HTML2PDF supports both server and client sides, the end-user doesn't need any software (Adobe Acrobat and Reader NOT required).
HTML2PDF (include PDFcamp + DocConverter COM) offers you the flexibility and speed you need to convert multiple HTML, DOC, RTF, TXT, PPT, XLS files into PDF format. Whatever the reason, pdf files can be created directly from MS Internet Explorer (or at background) and even emailed to a recipient/recipients simultaneously.
HTML2PDF Features:
* HTML2PDF can create page headers, footers and page numbers
* HTML2PDF can convert HTML, DOC, RTF, TXT, PPT, XLS files to PDF files on the fly
* HTML2PDF supports adjust paper orientation and size to accommodate HTML documents
* HTML2PDF supports nested tables
* HTML2PDF supports all elements in HTML document, include asp, cgi, css, Java Applets, flash, cookie etc.
* HTML2PDF supports dynamic page breaks with headers and footers
* HTML2PDF supports convert a URL or local file to PDF file
* HTML2PDF can convert .doc/.html/.rtf/.txt/.xls etc files to PDF files from a Command Line Tool, this Tool without any user intervention
* HTML2PDF supports command line operation (for manual use or inclusion in scripts)
How convert a HTML, DOC, RTF, TXT, PPT, XLS files to PDF files with DocConverter COM?
Step 1:
Please download and install the PDFcamp (PDF Writer) software,
http://www.verypdf.com/pdfcamp/pdfcamp_setup.exe
Step 2:
Please download and register the DocConverter COM software,
http://www.toppdf.com/pdfcamp/doc2pdf_com_trial.zip
Please register the pdfout.dll file in your system, for example,
~~~~~~~~~~~
regsvr32 pdfout.dll
~~~~~~~~~~~
Step 3:
Please run the html2pdf.exe software from the Command Line Window to try, the html2pdf.exe software is included in the DocConverter COM package,
For example:
html2pdf.exe "http://www.yahoo.com" "c:\yahoo.pdf"
html2pdf.exe "http://www.google.com/search?sourceid=navclient&ie=UTF-8&oe=UTF-8&q=pdf" "c:\google.pdf"
html2pdf.exe "C:\example.doc" "C:\example.pdf"
html2pdf.exe "C:\example.xls" "C:\example.pdf"
Now You have converted HTML, DOC, RTF, TXT, PPT, XLS files to PDF documents.
Step 5:
Now, you can call the html2pdf.exe software from your Delphi, C++, VB, BCB etc. applications.
HTML2PDF - Converting your HTML, DOC, RTF, TXT, PPT, XLS files to PDFs has never been easier! Combine several of your HTML, DOC, RTF, TXT, PPT, XLS files into a single PDF file. Convert a HTML file into a PDF file, or convert ANY file format to PDF file!
But f you want a simplier method to create PDF file without doing the above installations on your server to use PDF function in your scripts, then use FPDF.
FPDF is a PHP class which allows to generate PDF files with pure PHP, that is to say without using the PDFlib library. F from FPDF stands for Free: you may use it for any kind of usage and modify it to suit your needs.
Advantages: high level functions. Here is a list of its main features:
* Choice of measure unit, page format and margins
* Page header and footer management
* Automatic page break
* Automatic line break and text justification
* Image support (JPEG and PNG)
* Colors
* Links
* TrueType, Type1 and encoding support
* Page compression
FPDF requires no extension (except zlib to activate compression) and works with PHP4 and PHP5.
What languages can I use?
The class can produce documents in many languages other than the Western European ones: Central European, Cyrillic, Greek, Baltic and Thai, provided you own TrueType or Type1 fonts with the desired character set. Chinese, Japanese and Korean are supported too.
What about performance?
Of course, the generation speed of the document is less than with PDFlib. However, the performance penalty keeps very reasonable and suits in most cases, unless your documents are particularly complex or heavy.
Here, we are going to see on converting HTML 2 PDF using PHP. we would be seeing how to use some free open source PHP scripts to accomplish this file conversion.
FPDF: The PDF Generator
The first and the main base for this file conversion is FPDF library. FPDF is a pure PHP class to generate PDF files on the fly. Let us start the PDF generation with a simple Hello world display.
PHP Code:
AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$pdf->Output();
?>
To generate a pdf file, first we need to include library file fpdf.php. Then we need to create an FPDF object using the default constructor FPDF(). This constructor can be passed three values namely page orientation (portrait or landscape), measure unit, and page size (A4, A5, etc.,). By default pages are in A4 portrait and the measure unit is millimeter. It could have been specified explicitly with:
PHP Code:
$pdf=new FPDF('P','mm','A4');
It is possible to use landscape (L), other page formats (such as Letter and Legal) and measure units (pt, cm, in).
Then we have added a page to our pdf document with AddPage(). The origin is at the upper-left corner and the current position is by default placed at 1 cm from the borders; the margins can be changed with the function SetMargins().
To print a text, we need to first select a font with SetFont(). Let us select Arial bold 16:
PHP Code:
$pdf->SetFont('Arial','B',16);
We use Cell() function to output a text. A cell is a rectangular area, possibly framed, which contains some text. It is output at the current position. We specify its dimensions, its text (centered or aligned), if borders should be drawn, and where the current position moves after it (to the right, below or to the beginning of the next line). To add a frame, we would do this:
PHP Code:
$pdf->Cell(40,10,'Hello World !',1);
Finally, the document is closed and sent to the browser with Output(). We could have saved it in a file by passing the desired file name.
There are lot more functions in FPDF.
Need more info? click here.
HTML2FPDF: The Converter
HTML2FPDF is a PHP Class library that uses the FPDF class library to convert HTML files to PDF files. This library consist of three classes namely PDF, HTML2FPDF and FPDF (modified FPDF class). The class PDF extends the class HTML2FPDF that extends the class FPDF.
Now let us see, how to convert a sample html page into a PDF file using HTML2FPDF Library. The html page contains a table that lists a few nations with their corresponding national flags. Below is the code for the conversion.
PHP Code:
AddPage();
$fp = fopen("sample.html","r");
$strContent = fread($fp, filesize("sample.html"));
fclose($fp);
$pdf->WriteHTML($strContent);
$pdf->Output("sample.pdf");
echo "PDF file is generated successfully!";
?>
First, we need to include the html2fpdf.php file that contains the HTML2FPDF class and an object is created using the constructor HTML2FPDF(). Then a new page is added to the pdf document using the function AddPage(). The html contents are read from the sample.html file using file functions. Then the html contents are written in to the pdf format using WriteHTML() function. The above sample code with the sample html file and images and the html2fpdf class libraries can be downloaded here.
The HTML2FPDF class library will be working best with the XHTML 1.0. Also the class does not support all the features available with HTML. To know the supported HTML tags and other features, Please refer HTML 2 (F)PDF Project.
PDF files are very useful for data reporting. bcoz now every system having a pdf file reader.
The PDF functions in PHP can create PDF files using the PDFlib library created by Thomas Merz.
All of the functions in PDFlib and the PHP module have identical function names and parameters.
Using HTML2PDF we can convert html page to pdf.
HTML2PDF is a simple HTML to PDF tool which can quickly and easily convert thousands of HTML pages into PDF reports.
HTML2PDF (include PDFcamp + DocConverter COM) is the easiest way to convert your web pages and DOC, RTF, TXT, PPT, XLS files into PDF documents, HTML2PDF quickly and accurately transforms well-formed HTML, DOC, RTF, TXT, PPT, XLS files into PDF files, the HTML2PDF supports both server and client sides, the end-user doesn't need any software (Adobe Acrobat and Reader NOT required).
HTML2PDF (include PDFcamp + DocConverter COM) offers you the flexibility and speed you need to convert multiple HTML, DOC, RTF, TXT, PPT, XLS files into PDF format. Whatever the reason, pdf files can be created directly from MS Internet Explorer (or at background) and even emailed to a recipient/recipients simultaneously.
HTML2PDF Features:
* HTML2PDF can create page headers, footers and page numbers
* HTML2PDF can convert HTML, DOC, RTF, TXT, PPT, XLS files to PDF files on the fly
* HTML2PDF supports adjust paper orientation and size to accommodate HTML documents
* HTML2PDF supports nested tables
* HTML2PDF supports all elements in HTML document, include asp, cgi, css, Java Applets, flash, cookie etc.
* HTML2PDF supports dynamic page breaks with headers and footers
* HTML2PDF supports convert a URL or local file to PDF file
* HTML2PDF can convert .doc/.html/.rtf/.txt/.xls etc files to PDF files from a Command Line Tool, this Tool without any user intervention
* HTML2PDF supports command line operation (for manual use or inclusion in scripts)
How convert a HTML, DOC, RTF, TXT, PPT, XLS files to PDF files with DocConverter COM?
Step 1:
Please download and install the PDFcamp (PDF Writer) software,
http://www.verypdf.com/pdfcamp/pdfcamp_setup.exe
Step 2:
Please download and register the DocConverter COM software,
http://www.toppdf.com/pdfcamp/doc2pdf_com_trial.zip
Please register the pdfout.dll file in your system, for example,
~~~~~~~~~~~
regsvr32 pdfout.dll
~~~~~~~~~~~
Step 3:
Please run the html2pdf.exe software from the Command Line Window to try, the html2pdf.exe software is included in the DocConverter COM package,
For example:
html2pdf.exe "http://www.yahoo.com" "c:\yahoo.pdf"
html2pdf.exe "http://www.google.com/search?sourceid=navclient&ie=UTF-8&oe=UTF-8&q=pdf" "c:\google.pdf"
html2pdf.exe "C:\example.doc" "C:\example.pdf"
html2pdf.exe "C:\example.xls" "C:\example.pdf"
Now You have converted HTML, DOC, RTF, TXT, PPT, XLS files to PDF documents.
Step 5:
Now, you can call the html2pdf.exe software from your Delphi, C++, VB, BCB etc. applications.
HTML2PDF - Converting your HTML, DOC, RTF, TXT, PPT, XLS files to PDFs has never been easier! Combine several of your HTML, DOC, RTF, TXT, PPT, XLS files into a single PDF file. Convert a HTML file into a PDF file, or convert ANY file format to PDF file!
But f you want a simplier method to create PDF file without doing the above installations on your server to use PDF function in your scripts, then use FPDF.
FPDF is a PHP class which allows to generate PDF files with pure PHP, that is to say without using the PDFlib library. F from FPDF stands for Free: you may use it for any kind of usage and modify it to suit your needs.
Advantages: high level functions. Here is a list of its main features:
* Choice of measure unit, page format and margins
* Page header and footer management
* Automatic page break
* Automatic line break and text justification
* Image support (JPEG and PNG)
* Colors
* Links
* TrueType, Type1 and encoding support
* Page compression
FPDF requires no extension (except zlib to activate compression) and works with PHP4 and PHP5.
What languages can I use?
The class can produce documents in many languages other than the Western European ones: Central European, Cyrillic, Greek, Baltic and Thai, provided you own TrueType or Type1 fonts with the desired character set. Chinese, Japanese and Korean are supported too.
What about performance?
Of course, the generation speed of the document is less than with PDFlib. However, the performance penalty keeps very reasonable and suits in most cases, unless your documents are particularly complex or heavy.
Here, we are going to see on converting HTML 2 PDF using PHP. we would be seeing how to use some free open source PHP scripts to accomplish this file conversion.
FPDF: The PDF Generator
The first and the main base for this file conversion is FPDF library. FPDF is a pure PHP class to generate PDF files on the fly. Let us start the PDF generation with a simple Hello world display.
PHP Code:
AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$pdf->Output();
?>
To generate a pdf file, first we need to include library file fpdf.php. Then we need to create an FPDF object using the default constructor FPDF(). This constructor can be passed three values namely page orientation (portrait or landscape), measure unit, and page size (A4, A5, etc.,). By default pages are in A4 portrait and the measure unit is millimeter. It could have been specified explicitly with:
PHP Code:
$pdf=new FPDF('P','mm','A4');
It is possible to use landscape (L), other page formats (such as Letter and Legal) and measure units (pt, cm, in).
Then we have added a page to our pdf document with AddPage(). The origin is at the upper-left corner and the current position is by default placed at 1 cm from the borders; the margins can be changed with the function SetMargins().
To print a text, we need to first select a font with SetFont(). Let us select Arial bold 16:
PHP Code:
$pdf->SetFont('Arial','B',16);
We use Cell() function to output a text. A cell is a rectangular area, possibly framed, which contains some text. It is output at the current position. We specify its dimensions, its text (centered or aligned), if borders should be drawn, and where the current position moves after it (to the right, below or to the beginning of the next line). To add a frame, we would do this:
PHP Code:
$pdf->Cell(40,10,'Hello World !',1);
Finally, the document is closed and sent to the browser with Output(). We could have saved it in a file by passing the desired file name.
There are lot more functions in FPDF.
Need more info? click here.
HTML2FPDF: The Converter
HTML2FPDF is a PHP Class library that uses the FPDF class library to convert HTML files to PDF files. This library consist of three classes namely PDF, HTML2FPDF and FPDF (modified FPDF class). The class PDF extends the class HTML2FPDF that extends the class FPDF.
Now let us see, how to convert a sample html page into a PDF file using HTML2FPDF Library. The html page contains a table that lists a few nations with their corresponding national flags. Below is the code for the conversion.
PHP Code:
AddPage();
$fp = fopen("sample.html","r");
$strContent = fread($fp, filesize("sample.html"));
fclose($fp);
$pdf->WriteHTML($strContent);
$pdf->Output("sample.pdf");
echo "PDF file is generated successfully!";
?>
First, we need to include the html2fpdf.php file that contains the HTML2FPDF class and an object is created using the constructor HTML2FPDF(). Then a new page is added to the pdf document using the function AddPage(). The html contents are read from the sample.html file using file functions. Then the html contents are written in to the pdf format using WriteHTML() function. The above sample code with the sample html file and images and the html2fpdf class libraries can be downloaded here.
The HTML2FPDF class library will be working best with the XHTML 1.0. Also the class does not support all the features available with HTML. To know the supported HTML tags and other features, Please refer HTML 2 (F)PDF Project.
Monday, December 15, 2008
Simple php pagination
What is Pagination?
Think about if you have a mysql table with a thousand rows, and you want to allow the user to browse through the entire table. Displaying all the records in that table in one page would not be a good idea. Instead you should break the table up into smaller parts and let the user navigate through it. This is what pagination is, it allows you to break up large results from a database query, and displays a better navigation for the users.
The following code is a quick and dirty example of php/mysql pagination but if you are familiar with CSS, you can easily style the way the page navigation looks.
<?php
if(!empty($_GET["start"])){
$start = $_GET['start'];// To take care global variable if OFF
}else{
$start = 0;
}
if(!($start > 0)) { // This variable is set to zero for the first page
$start = 0;
}
$eu = ($start - 0);
$limit = 5; // No of records to be shown per page.
$whathis = $eu + $limit;
$back = $eu - $limit;
$next = $eu + $limit;
// to check the total number of records
$query = mysql_query(" SELECT * FROM <tablename> ") or die (mysql_error());
$total_rows = mysql_num_rows($query);
//select the record with limitation
$query = mysql_query(" SELECT * FROM <tablename> limit $eu, $limit ") or die (mysql_error());
//code for previous
if($back >=0) {
echo "<a href='yourpage.php?start=$back'><font face='Verdana' size='2'>PREV</font></a> ";
}
//code for the number of page with links
$i = 0;
$x = 1;
for($i=0;$i < $total_rows;$i=$i+$limit){
if($i != $eu){
echo "<a href='yourpage.php?start=$i'><font face='Verdana' size='2'>$x</font></a> ";
}else {
echo "<font face='Verdana' size='4' color=red>$x</font>";
} // Current page is not displayed as link and given font color red
$x = $x+1;
}
//code for next
if($whathis < $total_rows) {
echo "<a href='yourpage.php?start=$next'><font face='Verdana' size='2'>NEXT</font></a>";
}
?>
Think about if you have a mysql table with a thousand rows, and you want to allow the user to browse through the entire table. Displaying all the records in that table in one page would not be a good idea. Instead you should break the table up into smaller parts and let the user navigate through it. This is what pagination is, it allows you to break up large results from a database query, and displays a better navigation for the users.
The following code is a quick and dirty example of php/mysql pagination but if you are familiar with CSS, you can easily style the way the page navigation looks.
<?php
if(!empty($_GET["start"])){
$start = $_GET['start'];// To take care global variable if OFF
}else{
$start = 0;
}
if(!($start > 0)) { // This variable is set to zero for the first page
$start = 0;
}
$eu = ($start - 0);
$limit = 5; // No of records to be shown per page.
$whathis = $eu + $limit;
$back = $eu - $limit;
$next = $eu + $limit;
// to check the total number of records
$query = mysql_query(" SELECT * FROM <tablename> ") or die (mysql_error());
$total_rows = mysql_num_rows($query);
//select the record with limitation
$query = mysql_query(" SELECT * FROM <tablename> limit $eu, $limit ") or die (mysql_error());
//code for previous
if($back >=0) {
echo "<a href='yourpage.php?start=$back'><font face='Verdana' size='2'>PREV</font></a> ";
}
//code for the number of page with links
$i = 0;
$x = 1;
for($i=0;$i < $total_rows;$i=$i+$limit){
if($i != $eu){
echo "<a href='yourpage.php?start=$i'><font face='Verdana' size='2'>$x</font></a> ";
}else {
echo "<font face='Verdana' size='4' color=red>$x</font>";
} // Current page is not displayed as link and given font color red
$x = $x+1;
}
//code for next
if($whathis < $total_rows) {
echo "<a href='yourpage.php?start=$next'><font face='Verdana' size='2'>NEXT</font></a>";
}
?>
Thursday, December 11, 2008
Simple PHP Image Watermark
Have you ever wanted to add an alpha-transparent watermark to an image that you post on your website?
Here is a simple PHP script that watermarks JPEG and PNG images.
<?php
function watermark($sourcefile, $watermarkfile) {
# $sourcefile = Filename of the picture to be watermarked.
# $watermarkfile = Filename of the 24-bit PNG watermark file.
//Get the resource ids of the pictures
$watermarkfile_id = imagecreatefrompng($watermarkfile);
imageAlphaBlending($watermarkfile_id, false);
Here is a simple PHP script that watermarks JPEG and PNG images.
<?php
function watermark($sourcefile, $watermarkfile) {
# $sourcefile = Filename of the picture to be watermarked.
# $watermarkfile = Filename of the 24-bit PNG watermark file.
//Get the resource ids of the pictures
$watermarkfile_id = imagecreatefrompng($watermarkfile);
imageAlphaBlending($watermarkfile_id, false);
imageSaveAlpha($watermarkfile_id, true);
$fileType = strtolower(substr($sourcefile, strlen($sourcefile)-3));
switch($fileType) {
case("gif"):
$sourcefile_id = imagecreatefromgif($sourcefile);
break;
case("png"):
$sourcefile_id = imagecreatefrompng($sourcefile);
break;
default:
$sourcefile_id = imagecreatefromjpeg($sourcefile);
}
//Get the sizes of both pix
$sourcefile_width = imageSX($sourcefile_id);
$sourcefile_height = imageSY($sourcefile_id);
$watermarkfile_width = imageSX($watermarkfile_id);
$watermarkfile_height = imageSY($watermarkfile_id);
$dest_x = ( $sourcefile_width / 2 ) - ( $watermarkfile_width / 2 );
$dest_y = ( $sourcefile_height / 2 ) - ( $watermarkfile_height / 2 );
// if a gif, we have to upsample it to a truecolor image
if($fileType == "gif") {
// create an empty truecolor container
$tempimage = imagecreatetruecolor($sourcefile_width, $sourcefile_height);
// copy the 8-bit gif into the truecolor image
imagecopy($tempimage, $sourcefile_id, 0, 0, 0, 0, $sourcefile_width, $sourcefile_height);// copy the source_id int
$sourcefile_id = $tempimage;
}
imagecopy($sourcefile_id, $watermarkfile_id, $dest_x, $dest_y, 0, 0, $watermarkfile_width, $watermarkfile_height);
//Create a jpeg out of the modified picture
switch($fileType) {
// remember we do not need gif any more, so we use only png or jpeg.
// See the code above to see how we handle gifs
case("png"):
header("Content-type: image/png");
imagepng ($sourcefile_id);
break;
default:
header("Content-type: image/jpg");
imagejpeg ($sourcefile_id);
}
imagedestroy($sourcefile_id);
imagedestroy($watermarkfile_id);
}
watermark("main.jpg","watermark.png");
?>
Sample output below...No comment on the picture pls... its sacred y know..

$fileType = strtolower(substr($sourcefile, strlen($sourcefile)-3));
switch($fileType) {
case("gif"):
$sourcefile_id = imagecreatefromgif($sourcefile);
break;
case("png"):
$sourcefile_id = imagecreatefrompng($sourcefile);
break;
default:
$sourcefile_id = imagecreatefromjpeg($sourcefile);
}
//Get the sizes of both pix
$sourcefile_width = imageSX($sourcefile_id);
$sourcefile_height = imageSY($sourcefile_id);
$watermarkfile_width = imageSX($watermarkfile_id);
$watermarkfile_height = imageSY($watermarkfile_id);
$dest_x = ( $sourcefile_width / 2 ) - ( $watermarkfile_width / 2 );
$dest_y = ( $sourcefile_height / 2 ) - ( $watermarkfile_height / 2 );
// if a gif, we have to upsample it to a truecolor image
if($fileType == "gif") {
// create an empty truecolor container
$tempimage = imagecreatetruecolor($sourcefile_width, $sourcefile_height);
// copy the 8-bit gif into the truecolor image
imagecopy($tempimage, $sourcefile_id, 0, 0, 0, 0, $sourcefile_width, $sourcefile_height);// copy the source_id int
$sourcefile_id = $tempimage;
}
imagecopy($sourcefile_id, $watermarkfile_id, $dest_x, $dest_y, 0, 0, $watermarkfile_width, $watermarkfile_height);
//Create a jpeg out of the modified picture
switch($fileType) {
// remember we do not need gif any more, so we use only png or jpeg.
// See the code above to see how we handle gifs
case("png"):
header("Content-type: image/png");
imagepng ($sourcefile_id);
break;
default:
header("Content-type: image/jpg");
imagejpeg ($sourcefile_id);
}
imagedestroy($sourcefile_id);
imagedestroy($watermarkfile_id);
}
watermark("main.jpg","watermark.png");
?>
Sample output below...No comment on the picture pls... its sacred y know..
main.jpg
watermark.png
watermarked output jpeg
Saturday, November 22, 2008
Centering a popup div using css
Before, I was centering a div using javascript and it sucks and gives a lot of hassle then I found this script(about four months ago) which takes away all my headaches. Makes life 0.00000001% easier....hehe
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>coffee and paste - popup div center</title>
<style>
html, body {
height:100%;
}
#blackout {
visibility: hidden;
position: fixed;
left: 0;
top: 0;
width: 100%;
height: 100%;
display: none;
background-color: #000;
filter: alpha(opacity=80);
-moz-opacity: .8;
opacity: .8;
z-index: 9;
}
#divpopup{
position: fixed;
top: 50%;
left: 50%;
margin-top: -81px; /*half of the height plus a little to the top*/
margin-left: -150px; /*half of the width */
visibility: hidden;
display: none;
border: 1px solid #000;
background-color: #FFF;
color: #333;
padding: 0;
height: 150px;
width: 300px;
z-index: 10;
font-family: "Trebuchet MS", "Lucida Grande", Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
}
#divpop_head{
position:absolute;
top:0;
left:0;
width:100%;
background-color: #999999;
text-align:center;
padding:2px 0;
z-index:-1;
}
#close_pop{
float:right;
text-align:right;
cursor:pointer;
padding-right:10px;
}
#close_pop a{
text-decoration:none;
color: #333;
}
#close_pop a:hover{
color:#FF0000;
}
#pop_content{
clear:both;
padding: 10px;
}
</style>
<!--[if IE]>
<style type="text/css">
* {
padding: 0;
margin: 0;
}
html, body {
height: 100%;
overflow: auto;
}
#blackout {
position: absolute;
}
#divpopup {
position: absolute;
}
</style>
<![endif]-->
<script language="javascript" type="text/javascript">
function popup(sw) {
if (sw == 1) {
// Show popup
document.getElementById('blackout').style.visibility = 'visible';
document.getElementById('divpopup').style.visibility = 'visible';
document.getElementById('blackout').style.display = 'block';
document.getElementById('divpopup').style.display = 'block';
} else {
// Hide popup
document.getElementById('blackout').style.visibility = 'hidden';
document.getElementById('divpopup').style.visibility = 'hidden';
document.getElementById('blackout').style.display = 'none';
document.getElementById('divpopup').style.display = 'none';
}
}
</script>
</head>
<body>
<div id='blackout'> </div>
<div id='divpopup'>
<div id='divpop_head'>Coffee and Paste</div>
<div id='close_pop'onclick='popup(0)'><a href='#'>[close]</a></div>
<div id='pop_content'>
Thanks for visiting my blog....<br />
<a href='http://coffeeandpaste.blogspot.com/'>visit it again here </a><br />
<a href='http://monkeetech.blogspot.com/'>or my other blog here </a><br />
</div>
</div>
<a href='javascript:popup(1);'>Click here to test popup</a>
</body>
</html>
copy and paste the code above and paste it to your text editor and save it as html.
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>coffee and paste - popup div center</title>
<style>
html, body {
height:100%;
}
#blackout {
visibility: hidden;
position: fixed;
left: 0;
top: 0;
width: 100%;
height: 100%;
display: none;
background-color: #000;
filter: alpha(opacity=80);
-moz-opacity: .8;
opacity: .8;
z-index: 9;
}
#divpopup{
position: fixed;
top: 50%;
left: 50%;
margin-top: -81px; /*half of the height plus a little to the top*/
margin-left: -150px; /*half of the width */
visibility: hidden;
display: none;
border: 1px solid #000;
background-color: #FFF;
color: #333;
padding: 0;
height: 150px;
width: 300px;
z-index: 10;
font-family: "Trebuchet MS", "Lucida Grande", Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
}
#divpop_head{
position:absolute;
top:0;
left:0;
width:100%;
background-color: #999999;
text-align:center;
padding:2px 0;
z-index:-1;
}
#close_pop{
float:right;
text-align:right;
cursor:pointer;
padding-right:10px;
}
#close_pop a{
text-decoration:none;
color: #333;
}
#close_pop a:hover{
color:#FF0000;
}
#pop_content{
clear:both;
padding: 10px;
}
</style>
<!--[if IE]>
<style type="text/css">
* {
padding: 0;
margin: 0;
}
html, body {
height: 100%;
overflow: auto;
}
#blackout {
position: absolute;
}
#divpopup {
position: absolute;
}
</style>
<![endif]-->
<script language="javascript" type="text/javascript">
function popup(sw) {
if (sw == 1) {
// Show popup
document.getElementById('blackout').style.visibility = 'visible';
document.getElementById('divpopup').style.visibility = 'visible';
document.getElementById('blackout').style.display = 'block';
document.getElementById('divpopup').style.display = 'block';
} else {
// Hide popup
document.getElementById('blackout').style.visibility = 'hidden';
document.getElementById('divpopup').style.visibility = 'hidden';
document.getElementById('blackout').style.display = 'none';
document.getElementById('divpopup').style.display = 'none';
}
}
</script>
</head>
<body>
<div id='blackout'> </div>
<div id='divpopup'>
<div id='divpop_head'>Coffee and Paste</div>
<div id='close_pop'onclick='popup(0)'><a href='#'>[close]</a></div>
<div id='pop_content'>
Thanks for visiting my blog....<br />
<a href='http://coffeeandpaste.blogspot.com/'>visit it again here </a><br />
<a href='http://monkeetech.blogspot.com/'>or my other blog here </a><br />
</div>
</div>
<a href='javascript:popup(1);'>Click here to test popup</a>
</body>
</html>
copy and paste the code above and paste it to your text editor and save it as html.
Subscribe to:
Posts (Atom)
