📄 class.pdf.php
字号:
$res.= $this->filterText($v); } $res.= ")\n"; } $res.= ">>\nendobj"; return $res; break; } } /** * an action object, used to link to URLS initially */ function o_action($id, $action, $options = '') { if ($action != 'new') { $o = & $this->objects[$id]; } switch ($action) { case 'new': if (is_array($options)) { $this->objects[$id] = array('t'=>'action', 'info'=>$options, 'type'=>$options['type']); } else { // then assume a URI action $this->objects[$id] = array('t'=>'action', 'info'=>$options, 'type'=>'URI'); } break; case 'out': if ($this->encrypted) { $this->encryptInit($id); } $res = "\n".$id." 0 obj\n<< /Type /Action"; switch ($o['type']) { case 'ilink': // there will be an 'label' setting, this is the name of the destination $res.= "\n/S /GoTo\n/D ".$this->destinations[(string)$o['info']['label']]." 0 R"; break; case 'URI': $res.= "\n/S /URI\n/URI ("; if ($this->encrypted) { $res.= $this->filterText($this->ARC4($o['info'])); } else { $res.= $this->filterText($o['info']); } $res.= ")"; break; } $res.= "\n>>\nendobj"; return $res; break; } } /** * an annotation object, this will add an annotation to the current page. * initially will support just link annotations */ function o_annotation($id, $action, $options = '') { if ($action != 'new') { $o = & $this->objects[$id]; } switch ($action) { case 'new': // add the annotation to the current page $pageId = $this->currentPage; $this->o_page($pageId, 'annot', $id); // and add the action object which is going to be required switch ($options['type']) { case 'link': $this->objects[$id] = array('t'=>'annotation', 'info'=>$options); $this->numObj++; $this->o_action($this->numObj, 'new', $options['url']); $this->objects[$id]['info']['actionId'] = $this->numObj; break; case 'ilink': // this is to a named internal link $label = $options['label']; $this->objects[$id] = array('t'=>'annotation', 'info'=>$options); $this->numObj++; $this->o_action($this->numObj, 'new', array('type'=>'ilink', 'label'=>$label)); $this->objects[$id]['info']['actionId'] = $this->numObj; break; } break; case 'out': $res = "\n".$id." 0 obj\n<< /Type /Annot"; switch ($o['info']['type']) { case 'link': case 'ilink': $res.= "\n/Subtype /Link"; break; } $res.= "\n/A ".$o['info']['actionId']." 0 R"; $res.= "\n/Border [0 0 0]"; $res.= "\n/H /I"; $res.= "\n/Rect [ "; foreach($o['info']['rect'] as $v) { $res.= sprintf("%.4f ", $v); } $res.= "]"; $res.= "\n>>\nendobj"; return $res; break; } } /** * a page object, it also creates a contents object to hold its contents */ function o_page($id, $action, $options = '') { if ($action != 'new') { $o = & $this->objects[$id]; } switch ($action) { case 'new': $this->numPages++; $this->objects[$id] = array('t'=>'page', 'info'=>array('parent'=>$this->currentNode, 'pageNum'=>$this->numPages)); if (is_array($options)) { // then this must be a page insertion, array shoudl contain 'rid','pos'=[before|after] $options['id'] = $id; $this->o_pages($this->currentNode, 'page', $options); } else { $this->o_pages($this->currentNode, 'page', $id); } $this->currentPage = $id; //make a contents object to go with this page $this->numObj++; $this->o_contents($this->numObj, 'new', $id); $this->currentContents = $this->numObj; $this->objects[$id]['info']['contents'] = array(); $this->objects[$id]['info']['contents'][] = $this->numObj; $match = ($this->numPages%2 ? 'odd' : 'even'); foreach($this->addLooseObjects as $oId=>$target) { if ($target == 'all' || $match == $target) { $this->objects[$id]['info']['contents'][] = $oId; } } break; case 'content': $o['info']['contents'][] = $options; break; case 'annot': // add an annotation to this page if (!isset($o['info']['annot'])) { $o['info']['annot'] = array(); } // $options should contain the id of the annotation dictionary $o['info']['annot'][] = $options; break; case 'out': $res = "\n".$id." 0 obj\n<< /Type /Page"; $res.= "\n/Parent ".$o['info']['parent']." 0 R"; if (isset($o['info']['annot'])) { $res.= "\n/Annots ["; foreach($o['info']['annot'] as $aId) { $res.= " ".$aId." 0 R"; } $res.= " ]"; } $count = count($o['info']['contents']); if ($count == 1) { $res.= "\n/Contents ".$o['info']['contents'][0]." 0 R"; } else if ($count>1) { $res.= "\n/Contents [\n"; // reverse the page contents so added objects are below normal content //foreach (array_reverse($o['info']['contents']) as $cId) { // Back to normal now that I've got transparency working --Benj foreach ($o['info']['contents'] as $cId) { $res.= $cId." 0 R\n"; } $res.= "]"; } $res.= "\n>>\nendobj"; return $res; break; } } /** * the contents objects hold all of the content which appears on pages */ function o_contents($id, $action, $options = '') { if ($action != 'new') { $o = & $this->objects[$id]; } switch ($action) { case 'new': $this->objects[$id] = array('t'=>'contents', 'c'=>'', 'info'=>array()); if (strlen($options) && intval($options)) { // then this contents is the primary for a page $this->objects[$id]['onPage'] = $options; } else if ($options == 'raw') { // then this page contains some other type of system object $this->objects[$id]['raw'] = 1; } break; case 'add': // add more options to the decleration foreach ($options as $k=>$v) { $o['info'][$k] = $v; } case 'out': $tmp = $o['c']; $res = "\n".$id." 0 obj\n"; if (isset($this->objects[$id]['raw'])) { $res.= $tmp; } else { $res.= "<<"; if (function_exists('gzcompress') && $this->options['compression']) { // then implement ZLIB based compression on this content stream $res.= " /Filter /FlateDecode"; $tmp = gzcompress($tmp, 6); } if ($this->encrypted) { $this->encryptInit($id); $tmp = $this->ARC4($tmp); } foreach($o['info'] as $k=>$v) { $res.= "\n/".$k.' '.$v; } $res.= "\n/Length ".strlen($tmp) ." >>\nstream\n".$tmp."\nendstream"; } $res.= "\nendobj\n"; return $res; break; } } /** * an image object, will be an XObject in the document, includes description and data */ function o_image($id, $action, $options = '') { if ($action != 'new') { $o = & $this->objects[$id]; } switch ($action) { case 'new': // make the new object $this->objects[$id] = array('t'=>'image', 'data'=>&$options['data'], 'info'=>array()); $this->objects[$id]['info']['Type'] = '/XObject'; $this->objects[$id]['info']['Subtype'] = '/Image'; $this->objects[$id]['info']['Width'] = $options['iw']; $this->objects[$id]['info']['Height'] = $options['ih']; if (!isset($options['type']) || $options['type'] == 'jpg') { if (!isset($options['channels'])) { $options['channels'] = 3; } switch ($options['channels']) { case 1: $this->objects[$id]['info']['ColorSpace'] = '/DeviceGray'; break; default: $this->objects[$id]['info']['ColorSpace'] = '/DeviceRGB'; break; } $this->objects[$id]['info']['Filter'] = '/DCTDecode'; $this->objects[$id]['info']['BitsPerComponent'] = 8; } else if ($options['type'] == 'png') { $this->objects[$id]['info']['Filter'] = '/FlateDecode'; $this->objects[$id]['info']['DecodeParms'] = '<< /Predictor 15 /Colors '.$options['ncolor'].' /Columns '.$options['iw'].' /BitsPerComponent '.$options['bitsPerComponent'].'>>'; if (strlen($options['pdata'])) { $tmp = ' [ /Indexed /DeviceRGB '.(strlen($options['pdata']) /3-1) .' '; $this->numObj++; $this->o_contents($this->numObj, 'new'); $this->objects[$this->numObj]['c'] = $options['pdata']; $tmp.= $this->numObj.' 0 R'; $tmp.= ' ]'; $this->objects[$id]['info']['ColorSpace'] = $tmp; if (isset($options['transparency'])) { switch ($options['transparency']['type']) { case 'indexed': $tmp = ' [ '.$options['transparency']['data'].' '.$options['transparency']['data'].'] '; $this->objects[$id]['info']['Mask'] = $tmp; break; case 'color-key': $tmp = ' [ '. $options['transparency']['r'] . ' ' . $options['transparency']['r'] . $options['transparency']['g'] . ' ' . $options['transparency']['g'] . $options['transparency']['b'] . ' ' . $options['transparency']['b'] . ' ] '; $this->objects[$id]['info']['Mask'] = $tmp; pre_r($tmp); break; } } } else { if (isset($options['transparency'])) { switch ($options['transparency']['type']) { case 'indexed': $tmp = ' [ '.$options['transparency']['data'].' '.$options['transparency']['data'].'] '; $this->objects[$id]['info']['Mask'] = $tmp; break; case 'color-key': $tmp = ' [ '. $options['transparency']['r'] . ' ' . $options['transparency']['r'] . ' ' . $options['transparency']['g'] . ' ' . $options['transparency']['g'] . ' ' . $options['transparency']['b'] . ' ' . $options['transparency']['b'] . ' ] '; $this->objects[$id]['info']['Mask'] = $tmp; break; } } $this->objects[$id]['info']['ColorSpace'] = '/'.$options['color']; } $this->objects[$id]['info']['BitsPerComponent'] = $options['bitsPerComponent']; } // assign it a place in the named resource dictionary as an external object, according to // the label passed in with it. $this->o_pages($this->currentNode, 'xObject', array('label'=>$options['label'], 'objNum'=>$id)); // also make sure that we have the right procset object for it. $this->o_procset($this->procsetObjectId, 'add', 'ImageC'); break; case 'out': $tmp = &$o['data']; $res = "\n".$id." 0 obj\n<<"; foreach($o['info'] as $k=>$v) { $res.= "\n/".$k.' '.$v; } if ($this->encrypted) { $this->encryptInit($id); $tmp = $this->ARC4($tmp); } $res.= "\n/Length ".strlen($tmp) ." >>\nstream\n".$tmp."\nendstream\nendobj\n"; return $res; break; } } /** * graphics state object */ function o_extGState($id, $action, $options = "") { static $valid_params = array("LW", "LC", "LC", "LJ", "ML", "D", "RI", "OP", "op", "OPM", "Font", "BG", "BG2", "UCR", "TR", "TR2", "HT", "FL", "SM", "SA", "BM", "SMask", "CA", "ca", "AIS", "TK"); if ( $action != "new") { $o = & $this->objects[$id]; } switch ($action) { case "new": $this->objects[$id] = array('t' => 'extGState', 'info' => $options); // Tell the pages about the new resource $this->numStates++; $this->o_pages($this->currentNode, 'extGState', array("objNum" => $id, "stateNum" => $this->numStates)); break; case "out": $res = "\n" . $id . " 0 obj\n". "<< /Type /ExtGState\n"; foreach ($o["info"] as $parameter => $value) { if ( !in_array($parameter, $valid_params)) continue; $res.= "/$parameter $value\n"; } $res.= ">>\n".
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -