fpdf.php

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

PHP
2,044
字号
     * @access private     */    function _putimages()    {        $filter = ($this->compress) ? '/Filter /FlateDecode ' : '';        foreach ($this->images AS $file => $info) {            $this->_newobj();            $this->images[$file]['n'] = $this->n;            $this->_out('<</Type /XObject');            $this->_out('/Subtype /Image');            $this->_out('/Width ' . $info['w']);            $this->_out('/Height ' . $info['h']);            if ($info['cs'] == 'Indexed') {                $this->_out('/ColorSpace [/Indexed /DeviceRGB ' . (strlen($info['pal'])/ 3 - 1) . ' ' . ($this->n + 1) . ' 0 R]');            }            else {                $this->_out('/ColorSpace /' . $info['cs']);                if ($info['cs'] == 'DeviceCMYK') {                    $this->_out('/Decode [1 0 1 0 1 0 1 0]');                }            } // end if... else...            $this->_out('/BitsPerComponent ' . $info['bpc']);            $this->_out('/Filter /' . $info['f']);            if (isset($info['parms'])) {                $this->_out($info['parms']);            }            if (isset($info['trns']) && is_array($info['trns'])) {                $trns     = '';                $trns_cnt = count($info['trns']);                for ($i = 0; $i < $trns_cnt; $i++) {                    $trns .= $info['trns'][$i] . ' ' . $info['trns'][$i] . ' ';                }                $this->_out('/Mask [' . $trns . ']');            } // end if            $this->_out('/Length ' . strlen($info['data']) . '>>');            $this->_putstream($info['data']);            $this->_out('endobj');            // Palette            if ($info['cs'] == 'Indexed') {                $this->_newobj();                $pal = ($this->compress) ? gzcompress($info['pal']) : $info['pal'];                $this->_out('<<' . $filter . '/Length ' . strlen($pal) . '>>');                $this->_putstream($pal);                $this->_out('endobj');            } // end if        } // end while    } // end of the "_putimages()" method    /**     * Puts resources     *     * @access private     */    function _putresources()    {        $this->_putfonts();        $this->_putimages();        // Resource dictionary        $this->offsets[2] = strlen($this->buffer);        $this->_out('2 0 obj');        $this->_out('<</ProcSet [/PDF /Text /ImageB /ImageC /ImageI]');        $this->_out('/Font <<');        foreach ($this->fonts AS $font) {            $this->_out('/F' . $font['i'] . ' ' . $font['n'] . ' 0 R');        }        $this->_out('>>');        if (count($this->images)) {            $this->_out('/XObject <<');            foreach ($this->images AS $image) {                $this->_out('/I' . $image['i'] . ' ' . $image['n'] . ' 0 R');            }            $this->_out('>>');        }        $this->_out('>>');        $this->_out('endobj');    } // end of the "_putresources()" method    /**     * Puts document informations     *     * @access private     */    function _putinfo()    {        // loic1: PHP3 compatibility        // $this->_out('/Producer ' . $this->_textstring('FPDF ' . FPDF_VERSION));        $this->_out('/Producer ' . $this->_textstring('FPDF ' . $GLOBALS['FPDF_version']));        if (!empty($this->title)) {            $this->_out('/Title ' . $this->_textstring($this->title));        }        if (!empty($this->subject)) {            $this->_out('/Subject ' . $this->_textstring($this->subject));        }        if (!empty($this->author)) {            $this->_out('/Author ' . $this->_textstring($this->author));        }        if (!empty($this->keywords)) {            $this->_out('/Keywords ' . $this->_textstring($this->keywords));        }        if (!empty($this->creator)) {            $this->_out('/Creator ' . $this->_textstring($this->creator));        }        $this->_out('/CreationDate ' . $this->_textstring('D:' . date('YmdHis')));    } // end of the "_putinfo()" method    /**     * Puts catalog informations     *     * @access private     */    function _putcatalog()    {        $this->_out('/Type /Catalog');        $this->_out('/Pages 1 0 R');        if ($this->ZoomMode == 'fullpage') {            $this->_out('/OpenAction [3 0 R /Fit]');        } else if ($this->ZoomMode == 'fullwidth') {            $this->_out('/OpenAction [3 0 R /FitH null]');        } else if ($this->ZoomMode == 'real') {            $this->_out('/OpenAction [3 0 R /XYZ null null 1]');        } else if (!is_string($this->ZoomMode)) {            $this->_out('/OpenAction [3 0 R /XYZ null null ' . ($this->ZoomMode / 100) . ']');        }        if ($this->LayoutMode == 'single') {            $this->_out('/PageLayout /SinglePage');        } else if ($this->LayoutMode == 'continuous') {            $this->_out('/PageLayout /OneColumn');        } else if ($this->LayoutMode == 'two') {            $this->_out('/PageLayout /TwoColumnLeft');        }    } // end of the "_putcatalog()" method    /**     * Puts trailer     *     * @access private     */    function _puttrailer()    {        $this->_out('/Size ' . ($this->n + 1));        $this->_out('/Root ' . $this->n . ' 0 R');        $this->_out('/Info ' . ($this->n - 1) . ' 0 R');    } // end of the "_puttrailer()" method    /**     * Terminates document     *     * @access private     */    function _enddoc()    {        $this->_putpages();        $this->_putresources();        // Info        $this->_newobj();        $this->_out('<<');        $this->_putinfo();        $this->_out('>>');        $this->_out('endobj');        // Catalog        $this->_newobj();        $this->_out('<<');        $this->_putcatalog();        $this->_out('>>');        $this->_out('endobj');        // Cross-ref        $o = strlen($this->buffer);        $this->_out('xref');        $this->_out('0 ' . ($this->n + 1));        $this->_out('0000000000 65535 f ');        for ($i = 1; $i <= $this->n; $i++) {            $this->_out(sprintf('%010d 00000 n ', $this->offsets[$i]));        }        // Trailer        $this->_out('trailer');        $this->_out('<<');        $this->_puttrailer();        $this->_out('>>');        $this->_out('startxref');        $this->_out($o);        $this->_out('%%EOF');        $this->state=3;    } // end of the "_enddoc()" method    /**     * Starts a new page     *     * @param  string   The page orientation     *     * @access private     */    function _beginpage($orientation)    {        $this->page++;        $this->pages[$this->page] = '';        $this->state              = 2;        $this->x                  = $this->lMargin;        $this->y                  = $this->tMargin;        $this->lasth              = 0;        $this->FontFamily         = '';        // Page orientation        if (!$orientation) {            $orientation = $this->DefOrientation;        } else {            $orientation = strtoupper($orientation[0]);        }        if ($orientation != $this->DefOrientation) {            $this->OrientationChanges[$this->page] = TRUE;        }        if ($orientation != $this->CurOrientation) {            // Changes orientation            if ($orientation == 'P') {                $this->wPt = $this->fwPt;                $this->hPt = $this->fhPt;                $this->w   = $this->fw;                $this->h   = $this->fh;            }            else {                $this->wPt = $this->fhPt;                $this->hPt = $this->fwPt;                $this->w   = $this->fh;                $this->h   = $this->fw;            }            $this->PageBreakTrigger = $this->h - $this->bMargin;            $this->CurOrientation   = $orientation;        } // end if    } // end of the "_beginpage()" method    /**     * Ends page contents     *     * @access private     */    function _endpage()    {        $this->state=1;    } // end of the "_endpage()" method    /**     * Underlines text     *     * @param   double  The x position     * @param   double  The y position     * @param   string  The text     *     * @return  string  The underlined text     *     * @access  private     */    function _dounderline($x,$y,$txt)    {        $up = $this->CurrentFont['up'];        $ut = $this->CurrentFont['ut'];        $w  = $this->GetStringWidth($txt) + $this->ws * substr_count($txt, ' ');        return sprintf('%.2f %.2f %.2f %.2f re f', $x * $this->k, ($this->h - ($y - $up / 1000 * $this->FontSize)) * $this->k, $w * $this->k, -$ut / 1000 * $this->FontSizePt);    } // end of the "_dounderline()" method    /**     * Extracts info from a JPEG file     *     * @param   string  The file name and path     *     * @return  array   The images informations     *     * @access  private     */    function _parsejpg($file)    {        $a = GetImageSize($file);        if (!$a) {            $this->Error('Missing or incorrect image file: ' . $file);        }        if ($a[2] != 2) {            $this->Error('Not a JPEG file: ' . $file);        }        if (!isset($a['channels']) || $a['channels'] == 3) {            $colspace = 'DeviceRGB';        }        else if ($a['channels'] == 4) {            $colspace = 'DeviceCMYK';        }        else {            $colspace = 'DeviceGray';        }        $bpc = isset($a['bits']) ? $a['bits'] : 8;        // Reads whole file        $f    = fopen($file, 'rb');        $data = fread($f, filesize($file));        fclose($f);        return array('w'    => $a[0],                     'h'    => $a[1],                     'cs'   => $colspace,                     'bpc'  => $bpc,                     'f'    => 'DCTDecode',                     'data' => $data);    } // end of the "_parsejpg()" method    /**     * Reads a 4-byte integer from a file     *     * @param   string   The file name and path     *     * @return  integer  The 4-byte integer     *     * @access  private     *     * @see     _parsepng()     */    function _freadint($f)    {        $i = ord(fread($f, 1)) << 24;        $i += ord(fread($f, 1)) << 16;        $i += ord(fread($f, 1)) << 8;        $i += ord(fread($f, 1));        return $i;    } // end of the "_freadint()" method    /**     * Extracts info from a PNG file     *     * @param   string  The file name and path     *     * @return  array   The images informations     *     * @access  private     *     * @see     _freadint()     */    function _parsepng($file)    {        $f = fopen($file, 'rb');        if (!$f) {            $this->Error('Can\'t open image file: ' . $file);        }        // Checks signature        if (fread($f, 8) != chr(137) . 'PNG' . chr(13) . chr(10) . chr(26) . chr(10)) {            $this->Error('Not a PNG file: ' . $file);        }        // Reads header chunk        fread($f,4);        if (fread($f, 4) != 'IHDR') {            $this->Error('Incorrect PNG file: ' . $file);        }        $w   = $this->_freadint($f);        $h   = $this->_freadint($f);        $bpc = ord(fread($f,1));        if ($bpc > 8) {            $this->Error('16-bit depth not supported: ' . $file);        }        $ct  = ord(fread($f, 1));        if ($ct == 0) {            $colspace = 'DeviceGray';        }        else if ($ct == 2) {            $colspace = 'DeviceRGB';        }        else if ($ct == 3) {            $colspace = 'Indexed';        }        else {            $this->Error('Alpha channel not supported: ' . $file);        }        if (ord(fread($f, 1)) != 0) {            $this->Error('Unknown compression method: ' . $file);        }        if (ord(fread($f, 1)) != 0) {            $this->Error('Unknown filter method: ' . $file);        }        if (ord(fread($f, 1)) != 0) {            $this->Error('Interlacing not supported: ' . $file);        }        fread($f, 4);        $parms = '/DecodeParms <</Predictor 15 /Colors ' . ($ct == 2 ? 3 : 1)               . ' /BitsPerComponent ' . $bpc               . ' /Columns ' . $w . '>>';        // Scans chunks looking for palette, transparency and image data        $pal  = '';        $trns = '';        $data = '';        do {            $n    = $this->_freadint($f);            $type = fread($f, 4);            if ($type == 'PLTE') {                // Reads palette

⌨️ 快捷键说明

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