fpdf.php

来自「php绿色服务器,让大家试用greenamp」· PHP 代码 · 共 2,044 行 · 第 1/5 页

PHP
2,044
字号
        // Line width (0.2 mm)        $this->LineWidth = .567 / $this->k;        // Automatic page break        $this->SetAutoPageBreak(TRUE, 2 * $margin);        // Full width display mode        $this->SetDisplayMode('fullwidth');        // Compression        $this->SetCompression(TRUE);    } // end of the "FPDF()" constructor    /**     * Sets left margin of the page     *     * @param  double  The left margin     *     * @access public     */    function SetLeftMargin($margin)    {        $this->lMargin = $margin;        if ($this->page > 0 && $this->x < $margin) {            $this->x   = $margin;        }    } // end of the "SetLeftMargin()" method    /**     * Sets top margin of the page     *     * @param  double  The top margin     *     * @access public     */    function SetTopMargin($margin)    {        $this->tMargin = $margin;    } // end of the "SetTopMargin()" method    /**     * Sets right margin of the page     *     * @param  double  The right margin     *     * @access public     */    function SetRightMargin($margin)    {        $this->rMargin = $margin;    } // end of the "SetRightMargin()" method    /**     * Sets the title of the document (among the document properties)     *     * @param  string  The title of the document     *     * @access public     */    function SetTitle($title)    {        $this->title = $title;    } // end of the "SetTitle()" method    /**     * Sets the subject of the document (among the document properties)     *     * @param  string  The subject of the document     *     * @access public     */    function SetSubject($subject)    {        $this->subject = $subject;    } // end of the "SetSubject()" method    /**     * Sets the author of the document (among the document properties)     *     * @param  string  The author of the document     *     * @access public     */    function SetAuthor($author)    {        $this->author = $author;    } // end of the "SetAuthor()" method    /**     * Sets keywords of the document (among the document properties)     *     * @param  string  The keyword list for the document     *     * @access public     */    function SetKeywords($keywords)    {        $this->keywords = $keywords;    } // end of the "SetKeywords()" method    /**     * Sets the creator of the document (among the document properties)     *     * @param  string  The creator of the document     *     * @access public     */    function SetCreator($creator)    {        $this->creator = $creator;    } // end of the "SetCreator()" method    /**     * Defines an alias for the total number of pages     *     * @param  string  The alias string     *     * @access public     */    function AliasNbPages($alias = '{nb}')    {        $this->AliasNbPages = $alias;    } // end of the "AliasNbPages()" method    /**     * Selects a font     *     * @param   string   The font name     * @param   string   The font style (B, I, BI)     * @param   double   The font size (in points)     *     * @global  double   The character width     *     * @access  public     */    function SetFont($family, $style = '', $size = 0)    {        global $fpdf_charwidths;        $family     = strtolower($family);        if ($family == '') {            $family = $this->FontFamily;        }        if ($family == 'arial') {            $family = 'helvetica';        }        else if ($family == 'symbol' || $family == 'zapfdingbats') {            $style  = '';        }        $style      = strtoupper($style);        if (strpos(' ' . $style, 'U')) {            $this->underline = TRUE;            $style           = str_replace('U', '', $style);        } else {            $this->underline = FALSE;        }        if ($style == 'IB') {            $style  = 'BI';        }        if ($size == 0) {            $size   = $this->FontSizePt;        }        // Tests if the font is already selected        if ($this->FontFamily == $family && $this->FontStyle == $style && $this->FontSizePt == $size) {            return;        }        // Tests if used for the first time        $fontkey = $family . $style;        if (!isset($this->fonts[$fontkey])) {            // Checks if one of the standard fonts            if (isset($this->CoreFonts[$fontkey])) {                if (!isset($fpdf_charwidths[$fontkey])) {                    // Loads metric file                    $file     = $family;                    if ($family == 'times' || $family == 'helvetica') {                        $file .= strtolower($style);                    }                    $file     .= '.php';                    if (isset($GLOBALS['FPDF_font_path'])) {                        $file = $GLOBALS['FPDF_font_path'] . $file;                    }                    include($file);                    if (!isset($fpdf_charwidths[$fontkey])) {                        $this->Error('Could not include font metric file');                    }                } // end if                $i = count($this->fonts) + 1;                $this->fonts[$fontkey] = array('i'    => $i,                                               'type' => 'core',                                               'name' => $this->CoreFonts[$fontkey],                                               'up'   => -100,                                               'ut'   => 50,                                               'cw'   => $fpdf_charwidths[$fontkey]);            }            else {                $this->Error('Undefined font: ' . $family . ' ' . $style);            } // end if... else...        } // end if        // Selects it        $this->FontFamily  = $family;        $this->FontStyle   = $style;        $this->FontSizePt  = $size;        $this->FontSize    = $size / $this->k;        $this->CurrentFont = &$this->fonts[$fontkey];        if ($this->page > 0) {            $this->_out(sprintf('BT /F%d %.2f Tf ET', $this->CurrentFont['i'], $this->FontSizePt));        }    } // end of the "SetFont()" method    /**     * Sends the header of the page     *     * This method has to be implemented in your own inherited class     *     * @access public     */    function Header()    {        // void    } // end of the "Header()" method    /**     * Sends the footer of the page     *     * This method has to be implemented in your own inherited class     *     * @access public     */    function Footer()    {        // void    } // end of the "Footer()" method    /**     * Begin the document     *     * @access public     */    function Open()    {        $this->_begindoc();    } // end of the "Open()" method    /**     * Starts a new page     *     * @param  string  The page orientation (p, portrait, l or landscape)     *     * @access public     */    function AddPage($orientation = '')    {        // Backups some core variables        $family             = $this->FontFamily;        $style              = $this->FontStyle . ($this->underline ? 'U' : '');        $size               = $this->FontSizePt;        $lw                 = $this->LineWidth;        $dc                 = $this->DrawColor;        $fc                 = $this->FillColor;        $tc                 = $this->TextColor;        $cf                 = $this->ColorFlag;        // If a page is already defined close it before starting the new one        if ($this->page > 0) {            // Page footer            $this->InFooter = TRUE;            $this->Footer();            $this->InFooter = FALSE;            // Close page            $this->_endpage();        }        // Do start the new page        $this->_beginpage($orientation);        // Sets line cap style to square        $this->_out('2 J');        // Sets line width        $this->LineWidth = $lw;        $this->_out(sprintf('%.2f w', $lw * $this->k));        // Sets font        if ($family) {            $this->SetFont($family, $style, $size);        }        // Sets colors        $this->DrawColor = $dc;        if ($dc != '0 G') {            $this->_out($dc);        }        $this->FillColor = $fc;        if ($fc != '0 g') {            $this->_out($fc);        }        $this->TextColor = $tc;        $this->ColorFlag = $cf;        // Sets Page header        $this->Header();        // Restores line width        if ($this->LineWidth != $lw) {            $this->LineWidth = $lw;            $this->_out(sprintf('%.2f w', $lw * $this->k));        }        // Restores font        if ($family) {            $this->SetFont($family, $style, $size);        }        // Restores colors        if ($this->DrawColor!=$dc) {            $this->DrawColor = $dc;            $this->_out($dc);        }        if ($this->FillColor!=$fc) {            $this->FillColor = $fc;            $this->_out($fc);        }        $this->TextColor     = $tc;        $this->ColorFlag     = $cf;    } // end of the "AddPage()" method    /**     * Terminates and closes the document     *     * @access public     */    function Close()    {        // Terminates document        if ($this->page == 0) {            $this->AddPage();        }        // Displays the page footer        $this->InFooter = TRUE;        $this->Footer();        $this->InFooter = FALSE;        // Closes page and document        $this->_endpage();        $this->_enddoc();    } // end of the "Close()" method    /**     * Gets the current page number     *     * @return  integer  The current page number     *     * @access  public     */    function PageNo()    {        return $this->page;    } // end of the "PageNo()" method    /**     * Sets color for all stroking operations     *     * @param  integer  The red level (0 to 255)     * @param  integer  The green level (0 to 255)     * @param  integer  The blue level (0 to 255)     *     * @access public     */    function SetDrawColor($r, $g = -1, $b = -1)    {        if (($r == 0 && $g == 0 && $b == 0) || $g == -1) {            $this->DrawColor = sprintf('%.3f G', $r / 255);        } else {            $this->DrawColor = sprintf('%.3f %.3f %.3f RG', $r / 255, $g / 255, $b / 255);        } // end if... else...        // If a page is defined, applies this property        if ($this->page > 0) {            $this->_out($this->DrawColor);        }    } // end of the "SetDrawColor()" method    /**     * Sets color for all filling operations     *     * @param  integer  The red level (0 to 255)     * @param  integer  The green level (0 to 255)     * @param  integer  The blue level (0 to 255)     *     * @access public     */    function SetFillColor($r, $g = -1, $b =-1)    {

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?