php and pdf

 Documents and Pages

A PDF document is made up of a number of pages. Each page contains text and/or images.Put text onto
 the pages, and send the pages back to the browser when you're done.

 
 
<?php

require("../fpdf/fpdf.php"); // path to fpdf.php

$pdf = new FPDF(  );
$pdf->AddPage(  );
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello Out There!');
$pdf->Output(  );

?>
 follows the basic steps involved in creating a PDF document.

The cell concept in the FPDF Library is that of a rectangular area on the page that you can create and control.
 This cell can have a height, width, a border, and of course can contain text.
The basic syntax for the cell method is as follows:
Cell(float w [, float h [, string txt [, mixed border [, int ln [, 
string align [, int fill [, mixed link]]]]]]])

The first option is the width, then the height, then the text to be outputted, then border, then new line control, then its alignment, any fill colour for the text, and finally if you want the text to be an HTML link. So, for example, if we want to change our original example to have a border and be center
 aligned we would change the cell code to the following:
$pdf->Cell(90,10,'Hello Out There!',1,0,'C');

The cell method is used extensively while generating PDF documents with fpdf,

Demonstrating coordinates and line management

<?php
require("../fpdf/fpdf.php");

$pdf = new FPDF('P', 'in', 'Letter');
$pdf->AddPage(  );
$pdf->SetFont('Arial','B',24);
// Cell(W, H, 'text', Border, Return, 'Allign') - basic syntax
$pdf->Cell(0,0,'Top Left!',0,1,'L');
$pdf->Cell(6,0.5,'Top Right!',1,0,'R');
$pdf->ln(4.5);
$pdf->Cell(0,0,'This is the middle!',0,0,'C');
$pdf->ln(5.3);
$pdf->Cell(0,0,'Bottom Left!',0,0,'L');
$pdf->Cell(0,0,'Bottom Right!',0,0,'R');
$pdf->Output(  );
?>

Related Posts:
  • PHP operators are characters Artithmetic Operators OperatorDescription +Addition -Subtraction *Multiplication /Division %Modulus (remainder of a division) ++Increment --Decrement Assignment Operator Op… Read More
  • Multiple array in php If the ID, topic and description are all in the correct order in each comma delimited string you are supplying to the script, you could use the following to create a single array key'd by the ID: … Read More
  • Apache-Specific Functions These functions enable you to access Apache internal features—they form a high-level interface to some Apache API functions. Consequently, these functions are available only if you have compiled PHP as an Apache module. … Read More
  • SQL Injection Attacks This appeared to be an entirely custom application, and we had no prior knowledge of the application nor access to the source code: this was a "blind" attack. A bit of poking showed that this server ran Microsoft's IIS 6 alo… Read More
  • PHP Curl check for file existence a PHP program that downloads a pdf from a backend and save to a local drive. $url = "http://wedsite/test.pdf"; $path = "C:\\test.pdf;" downloadAndSave($url,$path); function downloadAndSave($urlS,$pathS) { $fp… Read More
  • PHP error: Cannot modify header information You cannot use header() once text has been output to the browser. As your header.php include presumably outputs HTML, header() cannot be used. You can solve this in a couple ways: Move the if statement above the heade… Read More
  • send images to mail box <?php $message = "<html><head></head><body>"; $message .= "<img src='http://exp.com/images/logo.jpg' alt='' /> </body> </html>"; $cleanedFrom="admin@abfdgd.com"; $headers = "Fr… Read More
  • keep your session secure php Use SSL when authenticating users or performing sensitive operations. Regenerate the session id whenever the security level changes (such as logging in). You can even regenerate the session id every request if you wish. H… Read More
  • How to create update or remove symbolic or soft link Linux Symbolic links , Symlink or Soft link in Unix are very important concept to understand and use in various UNIX operating systems e.g. Linux , Solaris or IBM AIX. Symlinks gives you so much power and flexibility that you can… Read More
  • Checking if a Host Is Alive Use PEAR's Net_Ping package: require 'Net/Ping.php'; $ping = new Net_Ping; if ($ping->checkhost('www.oreilly.com')) { print 'Reachable'; } else { print 'Unreachable'; } $data = $ping->ping('www.oreilly.com… Read More
  • Changing File Permissions by php Use chmod( ) to change the permissions of a file:  chmod('/home/user/secrets.txt',0400);   Use chown( ) to change a file's owner and chgrp( ) to change a file's group: <?php chown('/tmp/myfile.txt','skla… Read More
  • Opening a Remote File You want to open a file that's accessible to you via HTTP or FTP. Pass the file's URL to fopen( ):  $fh = fopen('http://www.example.com/robots.txt','r') or die($php_errormsg);     When fopen( ) is passed … Read More
  • PHP: How do I enable error reporting? he following enables all errors: ini_set('display_errors',1); ini_set('display_startup_errors',1); error_reporting(-1); See http://php.net/manual/en/errorfunc.configuration.php#ini.display-errors http://php.net/manu… Read More
  • SQL Injection Prevention the value should only be a positive integer value, since it's an id number. We do sometimes use other variables that could be a letter, or a string of text, for example, the search results pages. $variable = "0"; if (is… Read More
  • Download file using curl in php You would need to feed CURLOPT_URL the full URL to the file. Also if you want to download a file you might want to save it somewhere. Working example: $curl = curl_init(); $file = fopen("ls-lR.gz", 'w'); curl_setopt… Read More