source-class-Com.Tecnick.Pdf.MetaInfo

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:  * MetaInfo.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: /**
 19:  * Com\Tecnick\Pdf\MetaInfo
 20:  *
 21:  * Meta Informaton PDF class
 22:  *
 23:  * @since       2002-08-03
 24:  * @category    Library
 25:  * @package     Pdf
 26:  * @author      Nicola Asuni <info@tecnick.com>
 27:  * @copyright   2002-2017 Nicola Asuni - Tecnick.com LTD
 28:  * @license     http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
 29:  * @link        https://github.com/tecnickcom/tc-lib-pdf
 30:  */
 31: abstract class MetaInfo extends \Com\Tecnick\Pdf\Output
 32: {
 33:     /**
 34:      * TCPDF version.
 35:      *
 36:      * @var string
 37:      */
 38:     protected $version = '8.0.0';
 39: 
 40:     /**
 41:      * Time is seconds since EPOCH when the document was created.
 42:      *
 43:      * @var int
 44:      */
 45:     protected $doctime = 0;
 46: 
 47:     /**
 48:      *  Time is seconds since EPOCH when the document was modified.
 49:      *
 50:      * @var int
 51:      */
 52:     protected $docmodtime = 0;
 53: 
 54:     /**
 55:      * The name of the application that generates the PDF.
 56:      *
 57:      * If the document was converted to PDF from another format,
 58:      * the name of the conforming product that created the original document from which it was converted.
 59:      *
 60:      * @var string
 61:      */
 62:     protected $creator = 'TCPDF';
 63: 
 64:     /**
 65:      * The name of the person who created the document.
 66:      *
 67:      * @var string
 68:      */
 69:     protected $author = 'TCPDF';
 70: 
 71:     /**
 72:      * Subject of the document.
 73:      *
 74:      * @var string
 75:      */
 76:     protected $subject = '-';
 77: 
 78:     /**
 79:      * Title of the document.
 80:      *
 81:      * @var string
 82:      */
 83:     protected $title = 'PDF Document';
 84: 
 85:     /**
 86:      * Space-separated list of keywords associated with the document.
 87:      *
 88:      * @var string
 89:      */
 90:     protected $keywords = 'TCPDF';
 91: 
 92:     /**
 93:      * Additional XMP data to be appended just before the end of "x:xmpmeta" tag.
 94:      *
 95:      * @var string
 96:      */
 97:     protected $custom_xmp = '';
 98: 
 99:     /**
100:      * Set this to TRUE to add the default sRGB ICC color profile
101:      *
102:      * @var bool
103:      */
104:     protected $sRGB = false;
105: 
106:     /**
107:      * Viewer preferences dictionary controlling the way the document is to be presented on the screen or in print.
108:      * (Section 8.1 of PDF reference, "Viewer Preferences").
109:      *
110:      * @var array
111:      */
112:     protected $viewerpref = array();
113: 
114:     /**
115:      * Boolean flag to set the default document language direction.
116:      *    False = LTR = Left-To-Right.
117:      *    True = RTL = Right-To-Left.
118:      *
119:      * @val bool
120:      */
121:     protected $rtl = false;
122: 
123:     /**
124:      * Valid document zoom modes
125:      *
126:      * @var array
127:      */
128:     protected static $valid_zoom = array(
129:         'fullpage',
130:         'fullwidth',
131:         'real',
132:         'default'
133:     );
134: 
135:     /**
136:      * Return the program version.
137:      *
138:      * @return string
139:      */
140:     public function getVersion()
141:     {
142:         return $this->version;
143:     }
144: 
145:     /**
146:      * Set a field value only if it is not empty.
147:      *
148:      * @param strign $field Field name
149:      * @param srting $value Value to set
150:      */
151:     private function setNonEmptyFieldValue($field, $value)
152:     {
153:         if (!empty($value)) {
154:             $this->$field = $value;
155:         }
156:         return $this;
157:     }
158: 
159:     /**
160:      * Defines the creator of the document.
161:      * This is typically the name of the application that generates the PDF.
162:      *
163:      * @param string $creator The name of the creator.
164:      */
165:     public function setCreator($creator)
166:     {
167:         return $this->setNonEmptyFieldValue('creator', $creator);
168:     }
169: 
170:     /**
171:      * Defines the author of the document.
172:      *
173:      * @param string $author The name of the author.
174:      */
175:     public function setAuthor($author)
176:     {
177:         return $this->setNonEmptyFieldValue('author', $author);
178:     }
179: 
180:     /**
181:      * Defines the subject of the document.
182:      *
183:      * @param string $subject The subject.
184:      */
185:     public function setSubject($subject)
186:     {
187:         return $this->setNonEmptyFieldValue('subject', $subject);
188:     }
189: 
190:     /**
191:      * Defines the title of the document.
192:      *
193:      * @param string $title The title.
194:      */
195:     public function setTitle($title)
196:     {
197:         return $this->setNonEmptyFieldValue('title', $title);
198:     }
199: 
200:     /**
201:      * Associates keywords with the document, generally in the form 'keyword1 keyword2 ...'.
202:      *
203:      * @param string $keywords Space-separated list of keywords.
204:      */
205:     public function setKeywords($keywords)
206:     {
207:         return $this->setNonEmptyFieldValue('keywords', $keywords);
208:     }
209: 
210:     /**
211:      * Set the PDF version (check PDF reference for valid values).
212:      *
213:      * @param string $version PDF document version.
214:      *
215:      * @throw PdfException in case of error
216:      */
217:     public function setPDFVersion($version = '1.7')
218:     {
219:         if ($this->pdfa) { // PDF/A mode
220:             $this->pdfver = '1.4';
221:             return $this;
222:         }
223:         $isvalid = preg_match('/^[1-9]+[.][0-9]+$/', $version);
224:         if (empty($isvalid)) {
225:             throw new PdfException('Invalid PDF version format');
226:         }
227:         $this->pdfver = $version;
228:         return $this;
229:     }
230: 
231:     /**
232:      * Set the sRGB mode
233:      *
234:      * @param bool $enabled Set to true to add the default sRGB ICC color profile
235:      */
236:     public function setSRGB($enabled)
237:     {
238:         $this->srgb = (bool) $enabled;
239:         return $this;
240:     }
241: 
242:     /**
243:      * Format a text string for output.
244:      *
245:      * @param string $str String to escape.
246:      * @param int    $oid Current PDF object number.
247:      *
248:      * @return string escaped string.
249:      */
250:     protected function getOutTextString($str, $oid)
251:     {
252:         if ($this->isunicode) {
253:             $str = $this->uniconv->toUTF16BE($str);
254:         }
255:         return $this->encrypt->escapeDataString($str, $oid);
256:     }
257: 
258:     /**
259:      * Returns a formatted date for meta information
260:      *
261:      * @param int $time Time in seconds.
262:      *
263:      * @return string date-time string.
264:      */
265:     protected function getFormattedDate($time)
266:     {
267:         return substr_replace(date('YmdHisO', intval($time)), '\'', (0 - 2), 0).'\'';
268:     }
269: 
270:     /**
271:      * Returns a formatted date for XMP meta information
272:      *
273:      * @param int $time Time in seconds.
274:      *
275:      * @return string date-time string.
276:      */
277:     protected function getXMPFormattedDate($time)
278:     {
279:         return date('Y-m-dTH:i:sP', intval($time));
280:     }
281: 
282:     /**
283:      * Returns the producer string
284:      *
285:      * @return string
286:      */
287:     protected function getProducer()
288:     {
289:         return "\x54\x43\x50\x44\x46\x20"
290:         .$this->version
291:         ."\x20\x28\x68\x74\x74\x70\x73\x3a\x2f\x2f\x74\x63\x70\x64\x66\x2e\x6f\x72\x67\x29";
292:     }
293:     
294:     /**
295:      * Returns a formatted date for meta information
296:      *
297:      * @param int    $time Time in seconds.
298:      * @param int    $oid  Current PDF object number.
299:      *
300:      * @return string escaped date-time string.
301:      */
302:     protected function getOutDateTimeString($time, $oid)
303:     {
304:         if (empty($time)) {
305:             $time = $this->doctime;
306:         }
307:         return $this->getOutTextString('D:'.$this->getFormattedDate($time), $oid);
308:     }
309: 
310:     /**
311:      * Get the PDF output string for the Document Information Dictionary.
312:      * (ref. Chapter 14.3.3 Document Information Dictionary of PDF32000_2008.pdf)
313:      *
314:      * @return string
315:      */
316:     protected function getOutMetaInfo()
317:     {
318:         $oid = ++$this->pon;
319:         $this->objid['info'] = $oid;
320:         $out = $oid.' 0 obj'."\n"
321:         .'<<'
322:         .' /Creator '.$this->getOutTextString($this->creator, $oid)
323:         .' /Author '.$this->getOutTextString($this->author, $oid)
324:         .' /Subject '.$this->getOutTextString($this->subject, $oid)
325:         .' /Title '.$this->getOutTextString($this->title, $oid)
326:         .' /Keywords '.$this->getOutTextString($this->keywords, $oid)
327:         .' /Producer '.$this->getOutTextString($this->getProducer(), $oid)
328:         .' /CreationDate '.$this->getOutDateTimeString($this->doctime, $oid)
329:         .' /ModDate '.$this->getOutDateTimeString($this->docmodtime, $oid)
330:         .' /Trapped /False'
331:         .' >>'."\n"
332:         .'endobj'."\n";
333:         return $out;
334:     }
335: 
336:     /**
337:      * Escape some special characters (&lt; &gt; &amp;) for XML output.
338:      *
339:      * @param string $str Input string to escape.
340:      *
341:      * @return string
342:      */
343:     protected function getEscapedXML($str)
344:     {
345:         return strtr($str, array("\0" => '', '&' => '&amp;', '<' => '&lt;', '>' => '&gt;'));
346:     }
347: 
348:     /**
349:      * Set additional XMP data to be appended just before the end of "x:xmpmeta" tag.
350:      *
351:      * IMPORTANT:
352:      * This data is added as-is without controls, so you have to validate your data before using this method.
353:      *
354:      * @param string $xmp Custom XMP data.
355:      */
356:     public function setExtraXMP($xmp)
357:     {
358:         return $this->setNonEmptyFieldValue('custom_xmp', $xmp);
359:     }
360: 
361:     /**
362:      * Get the PDF output string for the XMP data object
363:      *
364:      * @return string
365:      *
366:      * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
367:      */
368:     protected function getOutXMP()
369:     {
370:         $uuid = 'uuid:'.substr($this->fileid, 0, 8)
371:         .'-'.substr($this->fileid, 8, 4)
372:         .'-'.substr($this->fileid, 12, 4)
373:         .'-'.substr($this->fileid, 16, 4)
374:         .'-'.substr($this->fileid, 20, 12);
375:         
376:         // @codingStandardsIgnoreStart
377:         $xmp = '<?xpacket begin="'.$this->uniconv->chr(0xfeff).'" id="W5M0MpCehiHzreSzNTczkc9d"?>'."\n"
378:         .'<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core 4.2.1-c043 52.372728, 2009/01/18-15:08:04">'."\n"
379:         ."\t".'<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">'."\n"
380:         ."\t\t".'<rdf:Description rdf:about="" xmlns:dc="http://purl.org/dc/elements/1.1/">'."\n"
381:         ."\t\t\t".'<dc:format>application/pdf</dc:format>'."\n"
382:         ."\t\t\t".'<dc:title>'."\n"
383:         ."\t\t\t\t".'<rdf:Alt>'."\n"
384:         ."\t\t\t\t\t".'<rdf:li xml:lang="x-default">'.$this->getEscapedXML($this->title).'</rdf:li>'."\n"
385:         ."\t\t\t\t".'</rdf:Alt>'."\n"
386:         ."\t\t\t".'</dc:title>'."\n"
387:         ."\t\t\t".'<dc:creator>'."\n"
388:         ."\t\t\t\t".'<rdf:Seq>'."\n"
389:         ."\t\t\t\t\t".'<rdf:li>'.$this->getEscapedXML($this->author).'</rdf:li>'."\n"
390:         ."\t\t\t\t".'</rdf:Seq>'."\n"
391:         ."\t\t\t".'</dc:creator>'."\n"
392:         ."\t\t\t".'<dc:description>'."\n"
393:         ."\t\t\t\t".'<rdf:Alt>'."\n"
394:         ."\t\t\t\t\t".'<rdf:li xml:lang="x-default">'.$this->getEscapedXML($this->subject).'</rdf:li>'."\n"
395:         ."\t\t\t\t".'</rdf:Alt>'."\n"
396:         ."\t\t\t".'</dc:description>'."\n"
397:         ."\t\t\t".'<dc:subject>'."\n"
398:         ."\t\t\t\t".'<rdf:Bag>'."\n"
399:         ."\t\t\t\t\t".'<rdf:li>'.$this->getEscapedXML($this->keywords).'</rdf:li>'."\n"
400:         ."\t\t\t\t".'</rdf:Bag>'."\n"
401:         ."\t\t\t".'</dc:subject>'."\n"
402:         ."\t\t".'</rdf:Description>'."\n"
403:         ."\t\t".'<rdf:Description rdf:about="" xmlns:xmp="http://ns.adobe.com/xap/1.0/">'."\n"
404:         ."\t\t\t".'<xmp:CreateDate>'.$this->getXMPFormattedDate($this->doctime).'</xmp:CreateDate>'."\n"
405:         ."\t\t\t".'<xmp:CreatorTool>'.$this->getEscapedXML($this->creator).'</xmp:CreatorTool>'."\n"
406:         ."\t\t\t".'<xmp:ModifyDate>'.$this->getXMPFormattedDate($this->docmodtime).'</xmp:ModifyDate>'."\n"
407:         ."\t\t\t".'<xmp:MetadataDate>'.$this->getXMPFormattedDate($this->doctime).'</xmp:MetadataDate>'."\n"
408:         ."\t\t".'</rdf:Description>'."\n"
409:         ."\t\t".'<rdf:Description rdf:about="" xmlns:pdf="http://ns.adobe.com/pdf/1.3/">'."\n"
410:         ."\t\t\t".'<pdf:Keywords>'.$this->getEscapedXML($this->keywords).'</pdf:Keywords>'."\n"
411:         ."\t\t\t".'<pdf:Producer>'.$this->getEscapedXML($this->getProducer()).'</pdf:Producer>'."\n"
412:         ."\t\t".'</rdf:Description>'."\n"
413:         ."\t\t".'<rdf:Description rdf:about="" xmlns:xmpMM="http://ns.adobe.com/xap/1.0/mm/">'."\n"
414:         ."\t\t\t".'<xmpMM:DocumentID>'.$uuid.'</xmpMM:DocumentID>'."\n"
415:         ."\t\t\t".'<xmpMM:InstanceID>'.$uuid.'</xmpMM:InstanceID>'."\n"
416:         ."\t\t".'</rdf:Description>'."\n";
417:         
418:         if ($this->pdfa) {
419:             $xmp .= "\t\t".'<rdf:Description rdf:about="" xmlns:pdfaid="http://www.aiim.org/pdfa/ns/id/">'."\n"
420:             ."\t\t\t".'<pdfaid:part>1</pdfaid:part>'."\n"
421:             ."\t\t\t".'<pdfaid:conformance>B</pdfaid:conformance>'."\n"
422:             ."\t\t".'</rdf:Description>'."\n";
423:             }
424: 
425:         // XMP extension schemas
426:         $xmp .= "\t\t".'<rdf:Description rdf:about="" xmlns:pdfaExtension="http://www.aiim.org/pdfa/ns/extension/" xmlns:pdfaSchema="http://www.aiim.org/pdfa/ns/schema#" xmlns:pdfaProperty="http://www.aiim.org/pdfa/ns/property#">'."\n"
427:         ."\t\t\t".'<pdfaExtension:schemas>'."\n"
428:         ."\t\t\t\t".'<rdf:Bag>'."\n"
429:         ."\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n"
430:         ."\t\t\t\t\t\t".'<pdfaSchema:namespaceURI>http://ns.adobe.com/pdf/1.3/</pdfaSchema:namespaceURI>'."\n"
431:         ."\t\t\t\t\t\t".'<pdfaSchema:prefix>pdf</pdfaSchema:prefix>'."\n"
432:         ."\t\t\t\t\t\t".'<pdfaSchema:schema>Adobe PDF Schema</pdfaSchema:schema>'."\n"
433:         ."\t\t\t\t\t".'</rdf:li>'."\n"
434:         ."\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n"
435:         ."\t\t\t\t\t\t".'<pdfaSchema:namespaceURI>http://ns.adobe.com/xap/1.0/mm/</pdfaSchema:namespaceURI>'."\n"
436:         ."\t\t\t\t\t\t".'<pdfaSchema:prefix>xmpMM</pdfaSchema:prefix>'."\n"
437:         ."\t\t\t\t\t\t".'<pdfaSchema:schema>XMP Media Management Schema</pdfaSchema:schema>'."\n"
438:         ."\t\t\t\t\t\t".'<pdfaSchema:property>'."\n"
439:         ."\t\t\t\t\t\t\t".'<rdf:Seq>'."\n"
440:         ."\t\t\t\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n"
441:         ."\t\t\t\t\t\t\t\t\t".'<pdfaProperty:category>internal</pdfaProperty:category>'."\n"
442:         ."\t\t\t\t\t\t\t\t\t".'<pdfaProperty:description>UUID based identifier for specific incarnation of a document</pdfaProperty:description>'."\n"
443:         ."\t\t\t\t\t\t\t\t\t".'<pdfaProperty:name>InstanceID</pdfaProperty:name>'."\n"
444:         ."\t\t\t\t\t\t\t\t\t".'<pdfaProperty:valueType>URI</pdfaProperty:valueType>'."\n"
445:         ."\t\t\t\t\t\t\t\t".'</rdf:li>'."\n"
446:         ."\t\t\t\t\t\t\t".'</rdf:Seq>'."\n"
447:         ."\t\t\t\t\t\t".'</pdfaSchema:property>'."\n"
448:         ."\t\t\t\t\t".'</rdf:li>'."\n"
449:         ."\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n"
450:         ."\t\t\t\t\t\t".'<pdfaSchema:namespaceURI>http://www.aiim.org/pdfa/ns/id/</pdfaSchema:namespaceURI>'."\n"
451:         ."\t\t\t\t\t\t".'<pdfaSchema:prefix>pdfaid</pdfaSchema:prefix>'."\n"
452:         ."\t\t\t\t\t\t".'<pdfaSchema:schema>PDF/A ID Schema</pdfaSchema:schema>'."\n"
453:         ."\t\t\t\t\t\t".'<pdfaSchema:property>'."\n"
454:         ."\t\t\t\t\t\t\t".'<rdf:Seq>'."\n"
455:         ."\t\t\t\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n"
456:         ."\t\t\t\t\t\t\t\t\t".'<pdfaProperty:category>internal</pdfaProperty:category>'."\n"
457:         ."\t\t\t\t\t\t\t\t\t".'<pdfaProperty:description>Part of PDF/A standard</pdfaProperty:description>'."\n"
458:         ."\t\t\t\t\t\t\t\t\t".'<pdfaProperty:name>part</pdfaProperty:name>'."\n"
459:         ."\t\t\t\t\t\t\t\t\t".'<pdfaProperty:valueType>Integer</pdfaProperty:valueType>'."\n"
460:         ."\t\t\t\t\t\t\t\t".'</rdf:li>'."\n"
461:         ."\t\t\t\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n"
462:         ."\t\t\t\t\t\t\t\t\t".'<pdfaProperty:category>internal</pdfaProperty:category>'."\n"
463:         ."\t\t\t\t\t\t\t\t\t".'<pdfaProperty:description>Amendment of PDF/A standard</pdfaProperty:description>'."\n"
464:         ."\t\t\t\t\t\t\t\t\t".'<pdfaProperty:name>amd</pdfaProperty:name>'."\n"
465:         ."\t\t\t\t\t\t\t\t\t".'<pdfaProperty:valueType>Text</pdfaProperty:valueType>'."\n"
466:         ."\t\t\t\t\t\t\t\t".'</rdf:li>'."\n"
467:         ."\t\t\t\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n"
468:         ."\t\t\t\t\t\t\t\t\t".'<pdfaProperty:category>internal</pdfaProperty:category>'."\n"
469:         ."\t\t\t\t\t\t\t\t\t".'<pdfaProperty:description>Conformance level of PDF/A standard</pdfaProperty:description>'."\n"
470:         ."\t\t\t\t\t\t\t\t\t".'<pdfaProperty:name>conformance</pdfaProperty:name>'."\n"
471:         ."\t\t\t\t\t\t\t\t\t".'<pdfaProperty:valueType>Text</pdfaProperty:valueType>'."\n"
472:         ."\t\t\t\t\t\t\t\t".'</rdf:li>'."\n"
473:         ."\t\t\t\t\t\t\t".'</rdf:Seq>'."\n"
474:         ."\t\t\t\t\t\t".'</pdfaSchema:property>'."\n"
475:         ."\t\t\t\t\t".'</rdf:li>'."\n"
476:         ."\t\t\t\t".'</rdf:Bag>'."\n"
477:         ."\t\t\t".'</pdfaExtension:schemas>'."\n"
478:         ."\t\t".'</rdf:Description>'."\n"
479:         ."\t".'</rdf:RDF>'."\n"
480:         .$this->custom_xmp
481:         .'</x:xmpmeta>'."\n"
482:         .'<?xpacket end="w"?>';
483:         // @codingStandardsIgnoreEnd
484: 
485:         $oid = ++$this->pon;
486:         $this->objid['xmp'] = $oid;
487:         $out = $oid.' 0 obj'."\n"
488:         .'<<'
489:         .' /Type /Metadata'
490:         .' /Subtype /XML'
491:         .' /Length '.strlen($xmp)
492:         .' >> stream'."\n"
493:         .$xmp."\n"
494:         .'endstream'."\n"
495:         .'endobj'."\n";
496: 
497:         return $out;
498:     }
499: 
500:     /**
501:      * Set the default document language direction.
502:      *
503:      * @param bool $enabled False = LTR = Left-To-Right; True = RTL = Right-To-Left.
504:      */
505:     public function setRTL($enabled)
506:     {
507:         $this->rtl = (bool) $enabled;
508:         return $this;
509:     }
510: 
511:     /**
512:      * Set the viewer preferences dictionary
513:      * controlling the way the document is to be presented on the screen or in print.
514:      *
515:      * @param array $pref Array of options (see Section 12.2 of PDF reference, "Viewer Preferences").
516:      */
517:     public function setViewerPreferences($pref)
518:     {
519:         $this->viewerpref = $pref;
520:         return $this;
521:     }
522: 
523:     /**
524:      * Sanitize the page box name and return the default 'CropBox' in case of error.
525:      *
526:      * @param string $name Entry name.
527:      *
528:      * @return string
529:      */
530:     protected function getPageBoxName($name)
531:     {
532:         $box = 'CropBox';
533:         if (isset($this->viewerpref[$name])) {
534:             $val = $this->viewerpref[$name];
535:             if (isset($this->page->$box[$val])) {
536:                 $box = $this->page->$box[$val];
537:             }
538:         }
539:         return ' /'.$name.' /'.$box;
540:     }
541: 
542:     /**
543:      * Sanitize the page box name and return the default 'CropBox' in case of error.
544:      *
545:      * @return string
546:      */
547:     protected function getPagePrintScaling()
548:     {
549:         $mode = 'AppDefault';
550:         if (isset($this->viewerpref['PrintScaling'])) {
551:             $name = strtolower($this->viewerpref['PrintScaling']);
552:             $valid = array(
553:                 'none'       => 'None',
554:                 'appdefault' => 'AppDefault',
555:             );
556:             if (isset($valid[$name])) {
557:                 $mode = $valid[$name];
558:             }
559:         }
560:         return ' /PrintScaling /'.$mode;
561:     }
562: 
563:     /**
564:      * Returns the Duplex mode for the Viewer Preferences
565:      *
566:      * @return string
567:      */
568:     protected function getDuplexMode()
569:     {
570:         $mode = 'none';
571:         if (isset($this->viewerpref['Duplex'])) {
572:             $name = strtolower($this->viewerpref['Duplex']);
573:             $valid = array(
574:                 'simplex'             => 'Simplex',
575:                 'duplexflipshortedge' => 'DuplexFlipShortEdge',
576:                 'duplexfliplongedge'  => 'DuplexFlipLongEdge',
577:             );
578:             if (isset($valid[$name])) {
579:                 $mode = $valid[$name];
580:             }
581:         }
582:         return ' /Duplex /'.$mode;
583:     }
584: 
585:     /**
586:      * Returns the Viewer Preference boolean entry.
587:      *
588:      * @param string $name Entry name.
589:      *
590:      * @return string
591:      */
592:     protected function getBooleanMode($name)
593:     {
594:         if (isset($this->viewerpref[$name])) {
595:             return ' /'.$name.' '.var_export((bool)$this->viewerpref[$name], true);
596:         }
597:         return '';
598:     }
599: 
600:     /**
601:      * Returns the PDF viewer preferences for the catalog section
602:      *
603:      * @return string
604:      */
605:     protected function getOutViewerPref()
606:     {
607:         $vpr = $this->viewerpref;
608:         $out = ' /ViewerPreferences <<';
609:         if ($this->rtl) {
610:             $out .= ' /Direction /R2L';
611:         } else {
612:             $out .= ' /Direction /L2R';
613:         }
614:         $out .= $this->getBooleanMode('HideToolbar');
615:         $out .= $this->getBooleanMode('HideMenubar');
616:         $out .= $this->getBooleanMode('HideWindowUI');
617:         $out .= $this->getBooleanMode('FitWindow');
618:         $out .= $this->getBooleanMode('CenterWindow');
619:         $out .= $this->getBooleanMode('DisplayDocTitle');
620:         if (isset($vpr['NonFullScreenPageMode'])) {
621:             $out .= ' /NonFullScreenPageMode /'.$this->page->getDisplay($vpr['NonFullScreenPageMode']);
622:         }
623:         $out .= $this->getPageBoxName('ViewArea');
624:         $out .= $this->getPageBoxName('ViewClip');
625:         $out .= $this->getPageBoxName('PrintArea');
626:         $out .= $this->getPageBoxName('PrintClip');
627:         $out .= $this->getPagePrintScaling();
628:         $out .= $this->getDuplexMode();
629:         $out .= $this->getBooleanMode('PickTrayByPDFSize');
630:         if (isset($vpr['PrintPageRange'])) {
631:             $PrintPageRangeNum = '';
632:             foreach ($vpr['PrintPageRange'] as $pnum) {
633:                 $PrintPageRangeNum .= ' '.($pnum - 1).'';
634:             }
635:             $out .= ' /PrintPageRange ['.$PrintPageRangeNum.' ]';
636:         }
637:         if (isset($vpr['NumCopies'])) {
638:             $out .= ' /NumCopies '.intval($vpr['NumCopies']);
639:         }
640:         $out .= ' >>';
641:         return $out;
642:     }
643: }
644: 
 

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