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

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