02/12/2004, 12:20
|
| | | Fecha de Ingreso: marzo-2004
Mensajes: 271
Antigüedad: 20 años, 1 mes Puntos: 0 | |
Código PHP: function _putinfo() { $this->_out('/Producer '.$this->_textstring('FPDF '.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'))); } function _putcatalog() { $this->_out('/Type /Catalog'); $this->_out('/Pages 1 0 R'); if($this->ZoomMode=='fullpage') $this->_out('/OpenAction [3 0 R /Fit]'); elseif($this->ZoomMode=='fullwidth') $this->_out('/OpenAction [3 0 R /FitH null]'); elseif($this->ZoomMode=='real') $this->_out('/OpenAction [3 0 R /XYZ null null 1]'); elseif(!is_string($this->ZoomMode)) $this->_out('/OpenAction [3 0 R /XYZ null null '.($this->ZoomMode/100).']'); if($this->LayoutMode=='single') $this->_out('/PageLayout /SinglePage'); elseif($this->LayoutMode=='continuous') $this->_out('/PageLayout /OneColumn'); elseif($this->LayoutMode=='two') $this->_out('/PageLayout /TwoColumnLeft'); } function _puttrailer() { $this->_out('/Size '.($this->n+1)); $this->_out('/Root '.$this->n.' 0 R'); $this->_out('/Info '.($this->n-1).' 0 R'); } 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; } function _beginpage($orientation) { $this->page++; $this->pages[$this->page]=''; $this->state=2; $this->x=$this->lMargin; $this->y=$this->tMargin; $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) { //Change 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; } } function _endpage() { //End of page contents $this->state=1; } function _newobj() { //Begin a new object $this->n++; $this->offsets[$this->n]=strlen($this->buffer); $this->_out($this->n.' 0 obj'); } function _dounderline($x,$y,$txt) { //Underline text $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); } function _parsejpg($file) { //Extract info from a JPEG file $a=GetImageSize($file); if(!$a) print('Missing or incorrect image file: '.$file); $file=DIR_S_CATALOG.DIR_WS_IMAGES.DEFAULT_IMAGE; //$this->Error('Missing or incorrect image file: '.$file); if($a[2]!=2) $this->Error('Not a JPEG file: '.$file); if(!isset($a['channels']) or $a['channels']==3) $colspace='DeviceRGB'; elseif($a['channels']==4) $colspace='DeviceCMYK'; else $colspace='DeviceGray'; $bpc=isset($a['bits']) ? $a['bits'] : 8; //Read whole file $f=fopen($file,'rb'); $data=''; while(!feof($f)) $data.=fread($f,4096); fclose($f); return array('w'=>$a[0],'h'=>$a[1],'cs'=>$colspace,'bpc'=>$bpc,'f'=>'DCTDecode','data'=>$data); } function _parsepng($file) { //Extract info from a PNG file $f=fopen($file,'rb'); if(!$f) $this->Error('Can\'t open image file: '.$file); //Check signature if(fread($f,8)!=chr(137).'PNG'.chr(13).chr(10).chr(26).chr(10)) $this->Error('Not a PNG file: '.$file); //Read 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'; elseif($ct==2) $colspace='DeviceRGB'; elseif($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.'>>'; //Scan chunks looking for palette, transparency and image data $pal=''; $trns=''; $data=''; do { $n=$this->_freadint($f); $type=fread($f,4); if($type=='PLTE') { //Read palette $pal=fread($f,$n); fread($f,4); } elseif($type=='tRNS') { //Read transparency info $t=fread($f,$n); if($ct==0) $trns=array(ord(substr($t,1,1))); elseif($ct==2) $trns=array(ord(substr($t,1,1)),ord(substr($t,3,1)),ord(substr($t,5,1))); else { $pos=strpos($t,chr(0)); if(is_int($pos)) $trns=array($pos); } fread($f,4); } elseif($type=='IDAT') { //Read image data block $data.=fread($f,$n); fread($f,4); } elseif($type=='IEND') break; else fread($f,$n+4); } while($n); if($colspace=='Indexed' and empty($pal)) $this->Error('Missing palette in '.$file); fclose($f); return array('w'=>$w,'h'=>$h,'cs'=>$colspace,'bpc'=>$bpc,'f'=>'FlateDecode','parms'=>$parms,'pal'=>$pal,'trns'=>$trns,'data'=>$data); } // Added for GIF Support function _parsegif($file) { //Function by Jerome Fenal ([email protected]) require_once 'pdf_gif.php'; //GIF class in pure PHP from Yamasoft ([url]http://www.yamasoft.com/php-gif.zip[/url]) $h=0; $w=0; $gif=new CGIF(); if (!$gif->loadFile($file, 0)) $this->Error("GIF parser: unable to open file $file"); if($gif->m_img->m_gih->m_bLocalClr) { $nColors = $gif->m_img->m_gih->m_nTableSize; $pal = $gif->m_img->m_gih->m_colorTable->toString(); if($bgColor != -1) { $bgColor = $this->m_img->m_gih->m_colorTable->colorIndex($bgColor); } $colspace='Indexed'; } elseif($gif->m_gfh->m_bGlobalClr) { $nColors = $gif->m_gfh->m_nTableSize; $pal = $gif->m_gfh->m_colorTable->toString(); if($bgColor != -1) { $bgColor = $gif->m_gfh->m_colorTable->colorIndex($bgColor); } $colspace='Indexed'; } else { $nColors = 0; $bgColor = -1; $colspace='DeviceGray'; $pal=''; } $trns=''; if($gif->m_img->m_bTrans && ($nColors > 0)) { $trns=array($gif->m_img->m_nTrans); } $data=$gif->m_img->m_data; $w=$gif->m_gfh->m_nWidth; $h=$gif->m_gfh->m_nHeight; if($colspace=='Indexed' and empty($pal)) $this->Error('Missing palette in '.$file); if ($this->compress) { $data=gzcompress($data); return array( 'w'=>$w, 'h'=>$h, 'cs'=>$colspace, 'bpc'=>8, 'f'=>'FlateDecode', 'pal'=>$pal, 'trns'=>$trns, 'data'=>$data); } else { return array( 'w'=>$w, 'h'=>$h, 'cs'=>$colspace, 'bpc'=>8, 'pal'=>$pal, 'trns'=>$trns, 'data'=>$data); } } // EOA function _freadint($f) { //Read a 4-byte integer from file $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; } function _textstring($s) { //Format a text string return '('.$this->_escape($s).')'; } function _escape($s) { //Add \ before \, ( and ) return str_replace(')','\\)',str_replace('(','\\(',str_replace('\\','\\\\',$s))); } function _putstream($s) { $this->_out('stream'); $this->_out($s); $this->_out('endstream'); } function _out($s) { //Add a line to the document if($this->state==2) $this->pages[$this->page].=$s."\n"; else $this->buffer.=$s."\n"; } //End of class } //Handle special IE contype request if(isset($HTTP_SERVER_VARS['HTTP_USER_AGENT']) and $HTTP_SERVER_VARS['HTTP_USER_AGENT']=='contype') { Header('Content-Type: application/pdf'); exit; } } ?>
ojala y me puedan ayudar |