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:   2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20:  21:  22:  23:  24:  25:  26:  27:  28:  29:  30:  31:  32:  33:  34:  35:  36:  37:  38:  39:  40:  41:  42:  43:  44:  45:  46:  47:  48:  49:  50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66:  67:  68:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270: 271: 272: 273: 274: 275: 276: 277: 278: 279: 280: 281: 282: 283: 284: 285: 286: 287: 288: 289: 290: 291: 292: 293: 294: 295: 296: 297: 298: 299: 300: 301: 302: 303: 304: 305: 306: 307: 308: 309: 310: 311: 312: 313: 314: 315: 316: 317: 318: 319: 320: 321: 322: 323: 324: 325: 326: 327: 328: 329: 330: 331: 332: 333: 334: 335: 336: 337: 338: 339: 340: 341: 342: 343: 344: 345: 346: 347: 348: 349: 350: 351: 352: 353: 354: 355: 356: 357: 358: 359: 360: 361: 362: 363: 364: 365: 366: 367: 368: 369: 370: 371: 372: 373: 374: 375: 376: 377: 378: 379: 380: 381: 382: 383: 384: 385: 386: 387: 388: 389: 390: 391: 392: 393: 394: 395: 396: 397: 398: 399: 400: 401: 402: 403: 404: 405: 406: 407: 408: 409: 410: 411: 412: 413: 414: 415: 416: 417: 418: 419: 420: 421: 422: 423: 424: 425: 426: 427: 428: 429: 430: 431: 432: 433: 434: 435: 436: 437: 438: 439: 440: 441: 442: 443: 444: 445: 446: 447: 448: 449: 450: 451: 452: 453: 454: 455: 456: 457: 458: 459: 460: 461: 462: 463: 464: 465: 466: 467: 468: 469: 470: 471: 472: 473: 474: 475: 476: 477: 478: 479: 480: 481: 482: 483: 484: 485: 486: 487: 488: 489: 490: 491: 492: 493: 494: 495: 496: 497: 498: 499: 500: 501: 502: 503: 504: 505: 506: 507: 508: 509: 510: 511: 512: 513: 514: 515: 516: 517: 518: 519: 520: 521: 522: 523: 524: 525: 526: 527: 528: 529: 530: 531: 532: 533: 534: 535: 536: 537: 538: 539: 540: 541: 542: 543: 544: 545: 546: 547: 548: 549: 550: 551: 552: 553: 554: 555: 556: 557: 558: 559: 560: 561: 562: 563: 564: 565: 566: 567: 568: 569: 570: 571: 572: 573: 574: 575: 576: 577: 578: 579: 580: 581: 582: 583: 584: 585: 586: 587: 588: 589: 590: 591: 592: 593: 594: 595: 596: 597: 598: 599: 600: 601: 602: 603: 604: 605: 606: 607: 608: 609: 610: 611: 612: 613: 614: 615: 616: 617: 618: 619: 620: 621: 622: 623: 624: 625: 626: 627: 628: 629: 630: 631: 632: 
<?php
/**
 * MetaInfo.php
 *
 * @since       2002-08-03
 * @category    Library
 * @package     Pdf
 * @author      Nicola Asuni <info@tecnick.com>
 * @copyright   2002-2017 Nicola Asuni - Tecnick.com LTD
 * @license     http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
 * @link        https://github.com/tecnickcom/tc-lib-pdf
 *
 * This file is part of tc-lib-pdf software library.
 */

namespace Com\Tecnick\Pdf;

/**
 * Com\Tecnick\Pdf\MetaInfo
 *
 * Meta Informaton PDF class
 *
 * @since       2002-08-03
 * @category    Library
 * @package     Pdf
 * @author      Nicola Asuni <info@tecnick.com>
 * @copyright   2002-2017 Nicola Asuni - Tecnick.com LTD
 * @license     http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
 * @link        https://github.com/tecnickcom/tc-lib-pdf
 */
abstract class MetaInfo extends \Com\Tecnick\Pdf\Output
{
    /**
     * TCPDF version.
     *
     * @var string
     */
    protected $version = '8.0.0';

    /**
     * Time is seconds since EPOCH when the document was created.
     *
     * @var int
     */
    protected $doctime = 0;

    /**
     *  Time is seconds since EPOCH when the document was modified.
     *
     * @var int
     */
    protected $docmodtime = 0;

    /**
     * The name of the application that generates the PDF.
     *
     * If the document was converted to PDF from another format,
     * the name of the conforming product that created the original document from which it was converted.
     *
     * @var string
     */
    protected $creator = 'TCPDF';

    /**
     * The name of the person who created the document.
     *
     * @var string
     */
    protected $author = 'TCPDF';

    /**
     * Subject of the document.
     *
     * @var string
     */
    protected $subject = '-';

    /**
     * Title of the document.
     *
     * @var string
     */
    protected $title = 'PDF Document';

    /**
     * Space-separated list of keywords associated with the document.
     *
     * @var string
     */
    protected $keywords = 'TCPDF';

    /**
     * Additional XMP data to be appended just before the end of "x:xmpmeta" tag.
     *
     * @var string
     */
    protected $custom_xmp = '';

    /**
     * Set this to TRUE to add the default sRGB ICC color profile
     *
     * @var bool
     */
    protected $sRGB = false;

    /**
     * Viewer preferences dictionary controlling the way the document is to be presented on the screen or in print.
     * (Section 8.1 of PDF reference, "Viewer Preferences").
     *
     * @var array
     */
    protected $viewerpref = array();

    /**
     * Boolean flag to set the default document language direction.
     *    False = LTR = Left-To-Right.
     *    True = RTL = Right-To-Left.
     *
     * @val bool
     */
    protected $rtl = false;

    /**
     * Return the program version.
     *
     * @return string
     */
    public function getVersion()
    {
        return $this->version;
    }

    /**
     * Set a field value only if it is not empty.
     *
     * @param strign $field Field name
     * @param srting $value Value to set
     */
    private function setNonEmptyFieldValue($field, $value)
    {
        if (!empty($value)) {
            $this->$field = $value;
        }
        return $this;
    }

    /**
     * Defines the creator of the document.
     * This is typically the name of the application that generates the PDF.
     *
     * @param string $creator The name of the creator.
     */
    public function setCreator($creator)
    {
        return $this->setNonEmptyFieldValue('creator', $creator);
    }

    /**
     * Defines the author of the document.
     *
     * @param string $author The name of the author.
     */
    public function setAuthor($author)
    {
        return $this->setNonEmptyFieldValue('author', $author);
    }

    /**
     * Defines the subject of the document.
     *
     * @param string $subject The subject.
     */
    public function setSubject($subject)
    {
        return $this->setNonEmptyFieldValue('subject', $subject);
    }

    /**
     * Defines the title of the document.
     *
     * @param string $title The title.
     */
    public function setTitle($title)
    {
        return $this->setNonEmptyFieldValue('title', $title);
    }

    /**
     * Associates keywords with the document, generally in the form 'keyword1 keyword2 ...'.
     *
     * @param string $keywords Space-separated list of keywords.
     */
    public function setKeywords($keywords)
    {
        return $this->setNonEmptyFieldValue('keywords', $keywords);
    }

    /**
     * Set the PDF version (check PDF reference for valid values).
     *
     * @param string $version PDF document version.
     *
     * @throw PdfException in case of error
     */
    public function setPDFVersion($version = '1.7')
    {
        if ($this->pdfa) { // PDF/A mode
            $this->pdfver = '1.4';
            return $this;
        }
        $isvalid = preg_match('/^[1-9]+[.][0-9]+$/', $version);
        if (empty($isvalid)) {
            throw new PdfException('Invalid PDF version format');
        }
        $this->pdfver = $version;
        return $this;
    }

    /**
     * Set the sRGB mode
     *
     * @param bool $enabled Set to true to add the default sRGB ICC color profile
     */
    public function setSRGB($enabled)
    {
        $this->srgb = (bool) $enabled;
        return $this;
    }

    /**
     * Format a text string for output.
     *
     * @param string $str String to escape.
     * @param int    $oid Current PDF object number.
     *
     * @return string escaped string.
     */
    protected function getOutTextString($str, $oid)
    {
        if ($this->isunicode) {
            $str = $this->uniconv->toUTF16BE($str);
        }
        return $this->encrypt->escapeDataString($str, $oid);
    }

    /**
     * Returns a formatted date for meta information
     *
     * @param int $time Time in seconds.
     *
     * @return string date-time string.
     */
    protected function getFormattedDate($time)
    {
        return substr_replace(date('YmdHisO', intval($time)), '\'', (0 - 2), 0).'\'';
    }

    /**
     * Returns a formatted date for XMP meta information
     *
     * @param int $time Time in seconds.
     *
     * @return string date-time string.
     */
    protected function getXMPFormattedDate($time)
    {
        return date('Y-m-dTH:i:sP', intval($time));
    }

    /**
     * Returns the producer string
     *
     * @return string
     */
    protected function getProducer()
    {
        return "\x54\x43\x50\x44\x46\x20"
        .$this->version
        ."\x20\x28\x68\x74\x74\x70\x73\x3a\x2f\x2f\x74\x63\x70\x64\x66\x2e\x6f\x72\x67\x29";
    }
    
    /**
     * Returns a formatted date for meta information
     *
     * @param int    $time Time in seconds.
     * @param int    $oid  Current PDF object number.
     *
     * @return string escaped date-time string.
     */
    protected function getOutDateTimeString($time, $oid)
    {
        if (empty($time)) {
            $time = $this->doctime;
        }
        return $this->getOutTextString('D:'.$this->getFormattedDate($time), $oid);
    }

    /**
     * Get the PDF output string for the Document Information Dictionary.
     * (ref. Chapter 14.3.3 Document Information Dictionary of PDF32000_2008.pdf)
     *
     * @return string
     */
    protected function getOutMetaInfo()
    {
        $oid = ++$this->pon;
        $this->objid['info'] = $oid;
        $out = $oid.' 0 obj'."\n"
        .'<<'
        .' /Creator '.$this->getOutTextString($this->creator, $oid)
        .' /Author '.$this->getOutTextString($this->author, $oid)
        .' /Subject '.$this->getOutTextString($this->subject, $oid)
        .' /Title '.$this->getOutTextString($this->title, $oid)
        .' /Keywords '.$this->getOutTextString($this->keywords, $oid)
        .' /Producer '.$this->getOutTextString($this->getProducer(), $oid)
        .' /CreationDate '.$this->getOutDateTimeString($this->doctime, $oid)
        .' /ModDate '.$this->getOutDateTimeString($this->docmodtime, $oid)
        .' /Trapped /False'
        .' >>'."\n"
        .'endobj'."\n";
        return $out;
    }

    /**
     * Escape some special characters (&lt; &gt; &amp;) for XML output.
     *
     * @param string $str Input string to escape.
     *
     * @return string
     */
    protected function getEscapedXML($str)
    {
        return strtr($str, array("\0" => '', '&' => '&amp;', '<' => '&lt;', '>' => '&gt;'));
    }

    /**
     * Set additional XMP data to be appended just before the end of "x:xmpmeta" tag.
     *
     * IMPORTANT:
     * This data is added as-is without controls, so you have to validate your data before using this method.
     *
     * @param string $xmp Custom XMP data.
     */
    public function setExtraXMP($xmp)
    {
        return $this->setNonEmptyFieldValue('custom_xmp', $xmp);
    }

    /**
     * Get the PDF output string for the XMP data object
     *
     * @return string
     *
     * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
     */
    protected function getOutXMP()
    {
        $uuid = 'uuid:'.substr($this->fileid, 0, 8)
        .'-'.substr($this->fileid, 8, 4)
        .'-'.substr($this->fileid, 12, 4)
        .'-'.substr($this->fileid, 16, 4)
        .'-'.substr($this->fileid, 20, 12);
        
        // @codingStandardsIgnoreStart
        $xmp = '<?xpacket begin="'.$this->uniconv->chr(0xfeff).'" id="W5M0MpCehiHzreSzNTczkc9d"?>'."\n"
        .'<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"
        ."\t".'<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">'."\n"
        ."\t\t".'<rdf:Description rdf:about="" xmlns:dc="http://purl.org/dc/elements/1.1/">'."\n"
        ."\t\t\t".'<dc:format>application/pdf</dc:format>'."\n"
        ."\t\t\t".'<dc:title>'."\n"
        ."\t\t\t\t".'<rdf:Alt>'."\n"
        ."\t\t\t\t\t".'<rdf:li xml:lang="x-default">'.$this->getEscapedXML($this->title).'</rdf:li>'."\n"
        ."\t\t\t\t".'</rdf:Alt>'."\n"
        ."\t\t\t".'</dc:title>'."\n"
        ."\t\t\t".'<dc:creator>'."\n"
        ."\t\t\t\t".'<rdf:Seq>'."\n"
        ."\t\t\t\t\t".'<rdf:li>'.$this->getEscapedXML($this->author).'</rdf:li>'."\n"
        ."\t\t\t\t".'</rdf:Seq>'."\n"
        ."\t\t\t".'</dc:creator>'."\n"
        ."\t\t\t".'<dc:description>'."\n"
        ."\t\t\t\t".'<rdf:Alt>'."\n"
        ."\t\t\t\t\t".'<rdf:li xml:lang="x-default">'.$this->getEscapedXML($this->subject).'</rdf:li>'."\n"
        ."\t\t\t\t".'</rdf:Alt>'."\n"
        ."\t\t\t".'</dc:description>'."\n"
        ."\t\t\t".'<dc:subject>'."\n"
        ."\t\t\t\t".'<rdf:Bag>'."\n"
        ."\t\t\t\t\t".'<rdf:li>'.$this->getEscapedXML($this->keywords).'</rdf:li>'."\n"
        ."\t\t\t\t".'</rdf:Bag>'."\n"
        ."\t\t\t".'</dc:subject>'."\n"
        ."\t\t".'</rdf:Description>'."\n"
        ."\t\t".'<rdf:Description rdf:about="" xmlns:xmp="http://ns.adobe.com/xap/1.0/">'."\n"
        ."\t\t\t".'<xmp:CreateDate>'.$this->getXMPFormattedDate($this->doctime).'</xmp:CreateDate>'."\n"
        ."\t\t\t".'<xmp:CreatorTool>'.$this->creator.'</xmp:CreatorTool>'."\n"
        ."\t\t\t".'<xmp:ModifyDate>'.$this->getXMPFormattedDate($this->docmodtime).'</xmp:ModifyDate>'."\n"
        ."\t\t\t".'<xmp:MetadataDate>'.$this->getXMPFormattedDate($this->doctime).'</xmp:MetadataDate>'."\n"
        ."\t\t".'</rdf:Description>'."\n"
        ."\t\t".'<rdf:Description rdf:about="" xmlns:pdf="http://ns.adobe.com/pdf/1.3/">'."\n"
        ."\t\t\t".'<pdf:Keywords>'.$this->getEscapedXML($this->keywords).'</pdf:Keywords>'."\n"
        ."\t\t\t".'<pdf:Producer>'.$this->getEscapedXML($this->getProducer()).'</pdf:Producer>'."\n"
        ."\t\t".'</rdf:Description>'."\n"
        ."\t\t".'<rdf:Description rdf:about="" xmlns:xmpMM="http://ns.adobe.com/xap/1.0/mm/">'."\n"
        ."\t\t\t".'<xmpMM:DocumentID>'.$uuid.'</xmpMM:DocumentID>'."\n"
        ."\t\t\t".'<xmpMM:InstanceID>'.$uuid.'</xmpMM:InstanceID>'."\n"
        ."\t\t".'</rdf:Description>'."\n";
        
        if ($this->pdfa) {
            $xmp .= "\t\t".'<rdf:Description rdf:about="" xmlns:pdfaid="http://www.aiim.org/pdfa/ns/id/">'."\n"
            ."\t\t\t".'<pdfaid:part>1</pdfaid:part>'."\n"
            ."\t\t\t".'<pdfaid:conformance>B</pdfaid:conformance>'."\n"
            ."\t\t".'</rdf:Description>'."\n";
            }

        // XMP extension schemas
        $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"
        ."\t\t\t".'<pdfaExtension:schemas>'."\n"
        ."\t\t\t\t".'<rdf:Bag>'."\n"
        ."\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n"
        ."\t\t\t\t\t\t".'<pdfaSchema:namespaceURI>http://ns.adobe.com/pdf/1.3/</pdfaSchema:namespaceURI>'."\n"
        ."\t\t\t\t\t\t".'<pdfaSchema:prefix>pdf</pdfaSchema:prefix>'."\n"
        ."\t\t\t\t\t\t".'<pdfaSchema:schema>Adobe PDF Schema</pdfaSchema:schema>'."\n"
        ."\t\t\t\t\t".'</rdf:li>'."\n"
        ."\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n"
        ."\t\t\t\t\t\t".'<pdfaSchema:namespaceURI>http://ns.adobe.com/xap/1.0/mm/</pdfaSchema:namespaceURI>'."\n"
        ."\t\t\t\t\t\t".'<pdfaSchema:prefix>xmpMM</pdfaSchema:prefix>'."\n"
        ."\t\t\t\t\t\t".'<pdfaSchema:schema>XMP Media Management Schema</pdfaSchema:schema>'."\n"
        ."\t\t\t\t\t\t".'<pdfaSchema:property>'."\n"
        ."\t\t\t\t\t\t\t".'<rdf:Seq>'."\n"
        ."\t\t\t\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n"
        ."\t\t\t\t\t\t\t\t\t".'<pdfaProperty:category>internal</pdfaProperty:category>'."\n"
        ."\t\t\t\t\t\t\t\t\t".'<pdfaProperty:description>UUID based identifier for specific incarnation of a document</pdfaProperty:description>'."\n"
        ."\t\t\t\t\t\t\t\t\t".'<pdfaProperty:name>InstanceID</pdfaProperty:name>'."\n"
        ."\t\t\t\t\t\t\t\t\t".'<pdfaProperty:valueType>URI</pdfaProperty:valueType>'."\n"
        ."\t\t\t\t\t\t\t\t".'</rdf:li>'."\n"
        ."\t\t\t\t\t\t\t".'</rdf:Seq>'."\n"
        ."\t\t\t\t\t\t".'</pdfaSchema:property>'."\n"
        ."\t\t\t\t\t".'</rdf:li>'."\n"
        ."\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n"
        ."\t\t\t\t\t\t".'<pdfaSchema:namespaceURI>http://www.aiim.org/pdfa/ns/id/</pdfaSchema:namespaceURI>'."\n"
        ."\t\t\t\t\t\t".'<pdfaSchema:prefix>pdfaid</pdfaSchema:prefix>'."\n"
        ."\t\t\t\t\t\t".'<pdfaSchema:schema>PDF/A ID Schema</pdfaSchema:schema>'."\n"
        ."\t\t\t\t\t\t".'<pdfaSchema:property>'."\n"
        ."\t\t\t\t\t\t\t".'<rdf:Seq>'."\n"
        ."\t\t\t\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n"
        ."\t\t\t\t\t\t\t\t\t".'<pdfaProperty:category>internal</pdfaProperty:category>'."\n"
        ."\t\t\t\t\t\t\t\t\t".'<pdfaProperty:description>Part of PDF/A standard</pdfaProperty:description>'."\n"
        ."\t\t\t\t\t\t\t\t\t".'<pdfaProperty:name>part</pdfaProperty:name>'."\n"
        ."\t\t\t\t\t\t\t\t\t".'<pdfaProperty:valueType>Integer</pdfaProperty:valueType>'."\n"
        ."\t\t\t\t\t\t\t\t".'</rdf:li>'."\n"
        ."\t\t\t\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n"
        ."\t\t\t\t\t\t\t\t\t".'<pdfaProperty:category>internal</pdfaProperty:category>'."\n"
        ."\t\t\t\t\t\t\t\t\t".'<pdfaProperty:description>Amendment of PDF/A standard</pdfaProperty:description>'."\n"
        ."\t\t\t\t\t\t\t\t\t".'<pdfaProperty:name>amd</pdfaProperty:name>'."\n"
        ."\t\t\t\t\t\t\t\t\t".'<pdfaProperty:valueType>Text</pdfaProperty:valueType>'."\n"
        ."\t\t\t\t\t\t\t\t".'</rdf:li>'."\n"
        ."\t\t\t\t\t\t\t\t".'<rdf:li rdf:parseType="Resource">'."\n"
        ."\t\t\t\t\t\t\t\t\t".'<pdfaProperty:category>internal</pdfaProperty:category>'."\n"
        ."\t\t\t\t\t\t\t\t\t".'<pdfaProperty:description>Conformance level of PDF/A standard</pdfaProperty:description>'."\n"
        ."\t\t\t\t\t\t\t\t\t".'<pdfaProperty:name>conformance</pdfaProperty:name>'."\n"
        ."\t\t\t\t\t\t\t\t\t".'<pdfaProperty:valueType>Text</pdfaProperty:valueType>'."\n"
        ."\t\t\t\t\t\t\t\t".'</rdf:li>'."\n"
        ."\t\t\t\t\t\t\t".'</rdf:Seq>'."\n"
        ."\t\t\t\t\t\t".'</pdfaSchema:property>'."\n"
        ."\t\t\t\t\t".'</rdf:li>'."\n"
        ."\t\t\t\t".'</rdf:Bag>'."\n"
        ."\t\t\t".'</pdfaExtension:schemas>'."\n"
        ."\t\t".'</rdf:Description>'."\n"
        ."\t".'</rdf:RDF>'."\n"
        .$this->custom_xmp
        .'</x:xmpmeta>'."\n"
        .'<?xpacket end="w"?>';
        // @codingStandardsIgnoreEnd

        $oid = ++$this->pon;
        $this->objid['xmp'] = $oid;
        $out = $oid.' 0 obj'."\n"
        .'<<'
        .' /Type /Metadata'
        .' /Subtype /XML'
        .' /Length '.strlen($xmp)
        .' >> stream'."\n"
        .$xmp."\n"
        .'endstream'."\n"
        .'endobj'."\n";

        return $out;
    }

    /**
     * Set the default document language direction.
     *
     * @param bool $enabled False = LTR = Left-To-Right; True = RTL = Right-To-Left.
     */
    public function setRTL($enabled)
    {
        $this->rtl = (bool) $enabled;
        return $this;
    }

    /**
     * Set the viewer preferences dictionary
     * controlling the way the document is to be presented on the screen or in print.
     *
     * @param array $pref Array of options (see Section 8.1 of PDF reference, "Viewer Preferences").
     */
    public function setViewerPreferences($pref)
    {
        $this->viewerpref = $pref;
        return $this;
    }

    /**
     * Sanitize the page box name and return the default 'CropBox' in case of error.
     *
     * @param string $name Entry name.
     *
     * @return string
     */
    protected function getPageBoxName($name)
    {
        $box = 'CropBox';
        if (isset($this->viewerpref[$name])) {
            $val = $this->viewerpref[$name];
            if (isset($this->page->$box[$val])) {
                $box = $this->page->$box[$val];
            }
        }
        return ' /'.$name.' /'.$box;
    }

    /**
     * Sanitize the page box name and return the default 'CropBox' in case of error.
     *
     * @return string
     */
    protected function getPagePrintScaling()
    {
        $mode = 'AppDefault';
        if (isset($this->viewerpref['PrintScaling'])) {
            $name = strtolower($this->viewerpref['PrintScaling']);
            $valid = array(
                'none'       => 'None',
                'appdefault' => 'AppDefault',
            );
            if (isset($valid[$name])) {
                $mode = $valid[$name];
            }
        }
        return ' /PrintScaling /'.$mode;
    }

    /**
     * Returns the Duplex mode for the Viewer Preferences
     *
     * @return string
     */
    protected function getDuplexMode()
    {
        $mode = 'none';
        if (isset($this->viewerpref['Duplex'])) {
            $name = strtolower($this->viewerpref['Duplex']);
            $valid = array(
                'simplex'             => 'Simplex',
                'duplexflipshortedge' => 'DuplexFlipShortEdge',
                'duplexfliplongedge'  => 'DuplexFlipLongEdge',
            );
            if (isset($valid[$name])) {
                $mode = $valid[$name];
            }
        }
        return ' /Duplex /'.$mode;
    }

    /**
     * Returns the Viewer Preference boolean entry.
     *
     * @param string $name Entry name.
     *
     * @return string
     */
    protected function getBooleanMode($name)
    {
        if (isset($this->viewerpref[$name])) {
            return ' /'.$name.' '.var_export((bool)$this->viewerpref[$name], true);
        }
        return '';
    }

    /**
     * Returns the PDF viewer preferences for the catalog section
     *
     * @return string
     */
    protected function getOutViewerPref()
    {
        $vpr = $this->viewerpref;
        $out = ' /ViewerPreferences <<';
        if ($this->rtl) {
            $out .= ' /Direction /R2L';
        } else {
            $out .= ' /Direction /L2R';
        }
        $out .= $this->getBooleanMode('HideToolbar');
        $out .= $this->getBooleanMode('HideMenubar');
        $out .= $this->getBooleanMode('HideWindowUI');
        $out .= $this->getBooleanMode('FitWindow');
        $out .= $this->getBooleanMode('CenterWindow');
        $out .= $this->getBooleanMode('DisplayDocTitle');
        if (isset($vpr['NonFullScreenPageMode'])) {
            $out .= ' /NonFullScreenPageMode /'.$this->page->getDisplay($vpr['NonFullScreenPageMode']);
        }
        $out .= $this->getPageBoxName('ViewArea');
        $out .= $this->getPageBoxName('ViewClip');
        $out .= $this->getPageBoxName('PrintArea');
        $out .= $this->getPageBoxName('PrintClip');
        $out .= $this->getPagePrintScaling();
        $out .= $this->getDuplexMode();
        $out .= $this->getBooleanMode('PickTrayByPDFSize');
        if (isset($vpr['PrintPageRange'])) {
            $PrintPageRangeNum = '';
            foreach ($vpr['PrintPageRange'] as $pnum) {
                $PrintPageRangeNum .= ' '.($pnum - 1).'';
            }
            $out .= ' /PrintPageRange ['.$PrintPageRangeNum.' ]';
        }
        if (isset($vpr['NumCopies'])) {
            $out .= ' /NumCopies '.intval($vpr['NumCopies']);
        }
        $out .= ' >>';
        return $out;
    }
}
 

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