Home >Backend Development >PHP Tutorial >PHP generate pdf file code (1/12)_PHP tutorial
The php code to generate pdf files is very complicated if it is really good at generating pdf files. Let's take a look at a complete php code to generate pdf files. It can generate pdf files from text files and can also use image files. Generate pdf file.
//php tutorial code to generate pdf files
/*
Generating pdf files is very complicated if it is really good. Let’s take a look at a complete PHP generates pdf file code. It can generate pdf files from text files or use image files to generate pdf files.
The files used to generate pdf files are
fpdf.php
chinese.php
picpdf.php
*/
//fpdf.php code
define('fpdf_version','1.6');
class fpdf
{
var $page; //current page number
var $n; //current object number
var $offsets; //array of object offsets
var $buffer; //buffer holding in-memory pdf
var $pages; //array containing pages
var $state; //current document state
var $compress; //compression flag
var $k; //scale factor (number of points in user unit)
var $deforientation; //default orientation
var $curorientation; //current orientation
var $pageformats; //available page formats
var $defpageformat; //default page format
var $curpageformat; //current page format
var $pagesizes; //array storing non-default page sizes
var $wpt,$hpt; //dimensions of current page in points
var $w,$h; //dimensions of current page in user unit
var $lmargin; //left margin
var $tmargin; //top margin
var $rmargin; //right margin
var $bmargin; //page break margin
var $cmargin; //cell margin
var $x,$y; //current position in user unit
var $lasth; //height of last printed cell
var $linewidth; //line width in user unit
var $corefonts; //array of standard font names
var $fonts; //array of used fonts
var $fontfiles; //array of font files
var $diffs; //array of encoding differences
var $fontfamily; //current font family
var $fontstyle; //current font style
var $underline; //underlining flag
var $currentfont; //current font info
var $fontsizept; //current font size in points
var $fontsize; //current font size in user unit
var $drawcolor; //commands for drawing color
var $fillcolor; //commands for filling color
var $textcolor; //commands for text color
var $colorflag; //indicates whether fill and text colors are different
var $ws; //word spacing
var $images; //array of used images
var $pagelinks; //array of links in pages
var $links; //array of internal links
var $autopagebreak; //automatic page breaking
var $pagebreaktrigger; //threshold used to trigger page breaks
var $inheader; //flag set when processing header
var $infooter; //flag set when processing footer
var $zoommode; //zoom display mode
var $layoutmode; //layout display mode
var $title; //title
var $subject; //subject
var $author; //author
var $keywords; //keywords
var $creator; //creator
var $aliasnbpages; //alias for total number of pages
var $pdfversion; //pdf version number
/*******************************************************************************
* *
* public methods *
* *
*******************************************************************************/
function fpdf($orientation='p', $unit='mm', $format='a4')
{
//some checks
$this->_dochecks();
//initialization of properties
$this->page=0;
$this->n=2;
$this->buffer='';
$this->pages=array();
$this->pagesizes=array();
$this->state=0;
$this->fonts=array();
$this->fontfiles=array();
$this->diffs=array();
$this->images=array();
$this->links=array();
$this->inheader=false;
$this->infooter=false;
$this->lasth=0;
$this->fontfamily='';
$this->fontstyle='';
$this->fontsizept=12;
$this->underline=false;
$this->drawcolor='0 g';
$this->fillcolor='0 g';
$this->textcolor='0 g';
$this->colorflag=false;
$this->ws=0;
//standard fonts
$this->corefonts=array('courier'=>'courier', 'courierb'=>'courier-bold', 'courieri'=>'courier-oblique', 'courierbi'=>'courier-boldoblique',
'helvetica'=>'helvetica', 'helveticab'=>'helvetica-bold', 'helveticai'=>'helvetica-oblique', 'helveticabi'=>'helvetica-boldoblique',
'times'=>'times-roman', 'timesb'=>'times-bold', 'timesi'=>'times-italic', 'timesbi'=>'times-bolditalic',
'symbol'=>'symbol', 'zapfdingbats'=>'zapfdingbats');
//scale factor
if($unit=='pt')1 2 3 4 5 6 7 8 9 10 11 12