source-class-Com.Tecnick.Pdf.Output

It appears that you are using AdBlocking software. The cost of running this website is covered by advertisements. If you like it please feel free to a small amount of money to secure the future of this website.
  1: <?php
  2: /**
  3:  * Output.php
  4:  *
  5:  * @since       2002-08-03
  6:  * @category    Library
  7:  * @package     Pdf
  8:  * @author      Nicola Asuni <info@tecnick.com>
  9:  * @copyright   2002-2017 Nicola Asuni - Tecnick.com LTD
 10:  * @license     http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
 11:  * @link        https://github.com/tecnickcom/tc-lib-pdf
 12:  *
 13:  * This file is part of tc-lib-pdf software library.
 14:  */
 15: 
 16: namespace Com\Tecnick\Pdf;
 17: 
 18: use \Com\Tecnick\Pdf\Font\Output as OutFont;
 19: 
 20: /**
 21:  * Com\Tecnick\Pdf\Output
 22:  *
 23:  * Output PDF data
 24:  *
 25:  * @since       2002-08-03
 26:  * @category    Library
 27:  * @package     Pdf
 28:  * @author      Nicola Asuni <info@tecnick.com>
 29:  * @copyright   2002-2017 Nicola Asuni - Tecnick.com LTD
 30:  * @license     http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
 31:  * @link        https://github.com/tecnickcom/tc-lib-pdf
 32:  */
 33: abstract class Output
 34: {
 35:     /**
 36:      * Array containing the ID of some PDF objects
 37:      *
 38:      * @var array
 39:      */
 40:     protected $objid = array();
 41: 
 42:     /**
 43:      * Returns the RAW PDF string
 44:      *
 45:      * @return string
 46:      */
 47:     public function getOutPDFString()
 48:     {
 49:         $out = $this->getOutPDFHeader()
 50:             .$this->getOutPDFBody();
 51:         $startxref = strlen($out);
 52:         $offset = $this->getPDFObjectOffsets($out);
 53:         $out .= $this->getOutPDFXref($offset)
 54:             .$this->getOutPDFTrailer()
 55:             .'startxref'."\n"
 56:             .$startxref."\n"
 57:             .'%%EOF'."\n";
 58:         // @TODO: sign the document ...
 59:         return $out;
 60:     }
 61: 
 62:     /**
 63:      * Returns the PDF document header
 64:      *
 65:      * @return string
 66:      */
 67:     protected function getOutPDFHeader()
 68:     {
 69:         return '%PDF-'.$this->pdfver."\n"
 70:             ."%\xE2\xE3\xCF\xD3\n";
 71:     }
 72: 
 73:     /**
 74:      * Returns the raw PDF Body section
 75:      *
 76:      * @return string
 77:      */
 78:     protected function getOutPDFBody()
 79:     {
 80:         $out = $this->page->getPdfPages($this->pon);
 81:         $out .= $this->graph->getOutExtGState($this->pon);
 82:         $this->pon = $this->graph->getObjectNumber();
 83:         $out .= $this->getOutOCG();
 84:         $outfont = new OutFont(
 85:             $this->font->getFonts(),
 86:             $this->pon,
 87:             $this->encrypt
 88:         );
 89:         $out .= $outfont->getFontsBlock();
 90:         $this->pon = $outfont->getObjectNumber();
 91:         $out .= $this->image->getOutImagesBlock($this->pon);
 92:         $this->pon = $outfont->getObjectNumber();
 93:         $out .= $this->color->getPdfSpotObjects($this->pon);
 94:         $out .= $this->graph->getOutGradientShaders($this->pon);
 95:         $this->pon = $this->graph->getObjectNumber();
 96:         $out .= $this->getOutXObjects();
 97:         $out .= $this->getOutResourcesDict();
 98:         $out .= $this->getOutDestinations();
 99:         $out .= $this->getOutEmbeddedFiles();
100:         $out .= $this->getOutAnnotations();
101:         $out .= $this->getOutJavascript();
102:         $out .= $this->getOutBookmarks();
103:         $enc = $this->encrypt->getEncryptionData();
104:         if ($enc['encrypted']) {
105:             $out .= $this->encrypt->getPdfEncryptionObj($this->pon);
106:         }
107:         $out .= $this->getOutSignatureFields();
108:         $out .= $this->getOutSignature();
109:         $out .= $this->getOutOutput();
110:         $out .= $this->getOutXMP();
111:         $out .= $this->getOutICC();
112:         $out .= $this->getOutCatalog();
113:         return $out;
114:     }
115: 
116:     /**
117:      * Returns the ordered offset array for each object
118:      *
119:      * @param string $data Raw PDF data
120:      *
121:      * @return array
122:      */
123:     protected function getPDFObjectOffsets($data)
124:     {
125:         preg_match_all('/(([0-9]+)[\s][0-9]+[\s]obj[\n])/i', $data, $matches, PREG_SET_ORDER|PREG_OFFSET_CAPTURE);
126:         $offset = array();
127:         foreach ($matches as $item) {
128:             $offset[($item[2][0])] = $item[2][1];
129:         }
130:         ksort($offset);
131:         return $offset;
132:     }
133: 
134:     /**
135:      * Returns the PDF XREF section
136:      *
137:      * @param array $offset Ordered offset array for each PDF object
138:      *
139:      * @return string
140:      */
141:     protected function getOutPDFXref($offset)
142:     {
143:         $out = 'xref'."\n"
144:             .'0 '.($this->pon + 1)."\n"
145:             .'0000000000 65535 f '."\n";
146:         $freegen = ($this->pon + 2);
147:         end($offset);
148:         $lastobj = key($offset);
149:         for ($idx = 1; $idx <= $lastobj; ++$idx) {
150:             if (isset($offset[$idx])) {
151:                 $out .= sprintf('%010d 00000 n '."\n", $offset[$idx]);
152:             } else {
153:                 $out .= sprintf('0000000000 %05d f '."\n", $freegen);
154:                 ++$freegen;
155:             }
156:         }
157:         return $out;
158:     }
159: 
160:     /**
161:      * Returns the PDF Trailer section
162:      *
163:      * @param array $offset Ordered offset array for each PDF object
164:      *
165:      * @return string
166:      */
167:     protected function getOutPDFTrailer()
168:     {
169:         $out = 'trailer'."\n"
170:             .'<<'
171:             .' /Size '.($this->pon + 1)
172:             .' /Root '.$this->objid['catalog'].' 0 R'
173:             .' /Info '.$this->objid['info'].' 0 R';
174:         $enc = $this->encrypt->getEncryptionData();
175:         if (!empty($enc['objid'])) {
176:             $out .= ' /Encrypt '.$enc['objid'].' 0 R';
177:         }
178:         $out .= ' /ID [ <'.$this->fileid.'> <'.$this->fileid.'> ]'
179:             .' >>'."\n";
180:         return $out;
181:     }
182: 
183:     /**
184:      * Returns the PDF object to include a standard sRGB_IEC61966-2.1 blackscaled ICC colour profile
185:      *
186:      * @return string
187:      */
188:     protected function getOutICC()
189:     {
190:         if (!$this->pdfa && !$this->sRGB) {
191:             return '';
192:         }
193:         
194:         $oid = ++$this->pon;
195:         $this->objid['srgbicc'] = $oid;
196:         $out = $oid.' 0 obj'."\n";
197:         $icc = file_get_contents(dirname(__FILE__).'/include/sRGB.icc.z');
198:         $icc = $this->encrypt->encryptString($icc, $oid);
199:         $out .= '<<'
200:             .'/N 3'
201:             .' /Filter /FlateDecode'
202:             .' /Length '.strlen($icc)
203:             .'>>'
204:             .' stream'."\n"
205:             .$icc."\n"
206:             .'endstream'."\n"
207:             .'endobj';
208:         return $out;
209:     }
210: 
211:     /**
212:      * Set OutputIntent to sRGB IEC61966-2.1 if required
213:      *
214:      * @return string
215:      */
216:     protected function getOutputIntents()
217:     {
218:         if (empty($this->objid['srgbicc']) || empty($this->objid['catalog'])) {
219:             return '';
220:         }
221:         $oid = $this->objid['catalog'];
222:         $out = ' /OutputIntents [<<'
223:             .' /Type /OutputIntent'
224:             .' /S /GTS_PDFA1'
225:             .' /OutputCondition '.$this->getOutTextString('sRGB IEC61966-2.1', $oid)
226:             .' /OutputConditionIdentifier '.$this->getOutTextString('sRGB IEC61966-2.1', $oid)
227:             .' /RegistryName '.$this->getOutTextString('http://www.color.org', $oid)
228:             .' /Info '.$this->getOutTextString('sRGB IEC61966-2.1', $oid)
229:             .' /DestOutputProfile '.$this->objid['srgbicc'].' 0 R'
230:             .' >>]';
231:         return $out;
232:     }
233: 
234:     /**
235:      * Set OutputIntent to sRGB IEC61966-2.1 if required
236:      *
237:      * @return string
238:      */
239:     protected function getPDFLayers()
240:     {
241:         if (empty($this->pdflayer) || empty($this->objid['catalog'])) {
242:             return '';
243:         }
244:         $oid = $this->objid['catalog'];
245:         $lyrobjs = '';
246:         $lyrobjs_off = '';
247:         $lyrobjs_lock = '';
248:         foreach ($this->pdflayer as $layer) {
249:             $layer_obj_ref = ' '.$layer['objid'].' 0 R';
250:             $lyrobjs .= $layer_obj_ref;
251:             if ($layer['view'] === false) {
252:                 $lyrobjs_off .= $layer_obj_ref;
253:             }
254:             if ($layer['lock']) {
255:                 $lyrobjs_lock .= $layer_obj_ref;
256:             }
257:         }
258:         $out = ' /OCProperties << /OCGs ['.$lyrobjs.' ]'
259:             .' /D <<'
260:             .' /Name '.$this->getOutTextString('Layers', $oid)
261:             .' /Creator '.$this->getOutTextString($this->creator, $oid)
262:             .' /BaseState /ON'
263:             .' /OFF ['.$lyrobjs_off.']'
264:             .' /Locked ['.$lyrobjs_lock.']'
265:             .' /Intent /View'
266:             .' /AS ['
267:             .' << /Event /Print /OCGs ['.$lyrobjs.'] /Category [/Print] >>'
268:             .' << /Event /View /OCGs ['.$lyrobjs.'] /Category [/View] >>'
269:             .' ]'
270:             .' /Order ['.$lyrobjs.']'
271:             .' /ListMode /AllPages'
272:             //.' /RBGroups ['..']'
273:             //.' /Locked ['..']'
274:             .' >>'
275:             .' >>';
276:         return $out;
277:     }
278: 
279:     /**
280:      * Returns the PDF Catalog entry
281:      *
282:      * @return string
283:      */
284:     protected function getOutCatalog()
285:     {
286:         // @TODO
287:         return '';
288:     }
289: 
290:     /**
291:      * Returns the PDF OCG entry
292:      *
293:      * @return string
294:      */
295:     protected function getOutOCG()
296:     {
297:         // @TODO
298:         return '';
299:     }
300: 
301:     /**
302:      * Returns the PDF XObjects entry
303:      *
304:      * @return string
305:      */
306:     protected function getOutXObjects()
307:     {
308:         // @TODO
309:         return '';
310:     }
311: 
312:     /**
313:      * Returns the PDF Resources Dictionary entry
314:      *
315:      * @return string
316:      */
317:     protected function getOutResourcesDict()
318:     {
319:         // @TODO
320:         return '';
321:     }
322: 
323:     /**
324:      * Returns the PDF Destinations entry
325:      *
326:      * @return string
327:      */
328:     protected function getOutDestinations()
329:     {
330:         // @TODO
331:         return '';
332:     }
333: 
334:     /**
335:      * Returns the PDF Embedded Files entry
336:      *
337:      * @return string
338:      */
339:     protected function getOutEmbeddedFiles()
340:     {
341:         // @TODO
342:         return '';
343:     }
344: 
345:     /**
346:      * Returns the PDF Annotations entry
347:      *
348:      * @return string
349:      */
350:     protected function getOutAnnotations()
351:     {
352:         // @TODO
353:         return '';
354:     }
355: 
356:     /**
357:      * Returns the PDF Javascript entry
358:      *
359:      * @return string
360:      */
361:     protected function getOutJavascript()
362:     {
363:         // @TODO
364:         return '';
365:     }
366: 
367:     /**
368:      * Returns the PDF Bookmarks entry
369:      *
370:      * @return string
371:      */
372:     protected function getOutBookmarks()
373:     {
374:         // @TODO
375:         return '';
376:     }
377: 
378:     /**
379:      * Returns the PDF Signature Fields entry
380:      *
381:      * @return string
382:      */
383:     protected function getOutSignatureFields()
384:     {
385:         // @TODO
386:         return '';
387:     }
388: 
389:     /**
390:      * Returns the PDF signarure entry
391:      *
392:      * @return string
393:      */
394:     protected function getOutSignature()
395:     {
396:         // @TODO
397:         return '';
398:     }
399: }
400: 
 

© 2004-2017 – Nicola Asuni - Tecnick.com - All rights reserved.
about - disclaimer - privacy