Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions lib/prince.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
// Copyright 2005-2014 YesLogic Pty. Ltd.
// http://www.princexml.com

use PrinceXMLPhp\Types\PdfProfile;

class Prince
{
private $exePath;
Expand Down Expand Up @@ -33,6 +35,7 @@ class Prince
private $pdfCreator;
private $encrypt;
private $encryptInfo;
private $profile;

public function __construct($exePath)
{
Expand Down Expand Up @@ -330,7 +333,19 @@ public function setEncryptInfo($keyBits,
}
}

/**
* Set optional optional PDF profiles
* @see https://www.princexml.com/doc/pdf-profiles
* @example $princeWrapper->setProfile(PdfProfile::createX32002());
* @param PdfProfile $profile
* @return self
*/
public function setProfile(PdfProfile $profile)
{
$this->profile = sprintf('%s', $profile);

return $this;
}

// Convert an XML or HTML file to a PDF file.
// The name of the output PDF file will be the same as the name of the
Expand Down Expand Up @@ -567,6 +582,11 @@ private function getCommandLine()
$cmdline .= '--encrypt ' . $this->encryptInfo;
}

if( $this->profile != '' )
{
$cmdline .= '--profile="'. $this->profile .'" ';
}

return $cmdline;
}

Expand Down
27 changes: 27 additions & 0 deletions lib/readme.html
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ <h2>Configuration methods</h2>
<li><a href="#setpdfcreator"><code>setPDFCreator</code></a></li>
<li><a href="#setencrypt"><code>setEncrypt</code></a></li>
<li><a href="#setencryptinfo"><code>setEncryptInfo</code></a></li>
<li><a href="#setProfile"><code>setProfile</code></a></li>
</ul>

<hr/>
Expand Down Expand Up @@ -818,6 +819,32 @@ <h2>Configuration methods</h2>

<hr>

<a name="setprofile">

<pre>
public function setProfile(PdfProfile $profile)
</pre>

<p>
Set optional pdf profile
Prince supports optional PDF profiles, which can be selected. Available profiles are:
PDF/A-1b,
PDF/A-3b,
PDF/X-1a:2001,
PDF/X-1a:2003,
PDF/X-3:2002,
PDF/X-3:2003,
PDF/X-4
More information <a href="https://www.princexml.com/doc/pdf-profiles">here</a>.
</p>

<dl>
<dt><code>PdfProfile $profile</code></dt>
<dd>Pass a PdfProfile object to set one of the specific profiles.</dd>
</dl>

<hr>

<p>
Copyright &#xA9; 2005-2013 YesLogic Pty. Ltd.
</p>
Expand Down
6 changes: 3 additions & 3 deletions src/PrinceXMLPhp/PrinceWrapper.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<?php

/*
/**
* This file is part of the PrinceXMLPhp.
*
* (c) Gridonic <hello@gridonic.ch>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace PrinceXMLPhp;

require_once __DIR__.'/../../lib/prince.php';

use \Prince;
use Prince;

class PrinceWrapper extends Prince
{
Expand Down
95 changes: 95 additions & 0 deletions src/PrinceXMLPhp/Types/AbstractEnumType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?php

namespace PrinceXMLPhp\Types;

use PrinceXMLPhp\Types\Exceptions\InvalidEnumTypeException;

/**
* AbstractEnumType allows to define type safe value classes for a predefined set of possible values.
* @package PrinceXMLPhp
*/
abstract class AbstractEnumType
{
/**
* Current active value.
*
* @var mixed
*/
private $value;

/**
* AbstractEnumType constructor.
* @param mixed $value the current value
*/
public function __construct($value)
{
$this->setValue($value);
}

/**
* Provides the data suitable for selecting correct enum value,
* e.g. list-based HTML elements.
* @return array
*/
public function getListData()
{
return $this->getAllowedValues();
}

/**
* Must return the allowed values for this type.
*
* @return array
*/
abstract protected function getAllowedValues();

/**
* Checks if the passed value is allowed.
*
* @param $value
* @return bool
*/
final protected function isAllowed($value)
{
return in_array($value, $this->getAllowedValues(), true);
}

/**
* Returns the current value.
*
* @return mixed
*/
final public function getValue()
{
return $this->value;
}

/**
* Sets the current value.
* @throws InvalidEnumTypeException If given value does not match
* @param mixed $value
*/
final public function setValue($value)
{
if (!$this->isAllowed($value))
{
throw new InvalidEnumTypeException(
sprintf(
'"%s" is not allowed as a value for %s.',
$value,
get_class($this)
)
);
}
$this->value = $value;
}

/**
* @inheritdoc
*/
final public function __toString()
{
return $this->value;
}

}
14 changes: 14 additions & 0 deletions src/PrinceXMLPhp/Types/Exceptions/InvalidEnumTypeException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace PrinceXMLPhp\Types\Exceptions;

use Exception;

/**
* Class InvalidEnumTypeException
* @package PrinceXMLPhp\Types\Exceptions
*/
class InvalidEnumTypeException extends Exception
{

}
92 changes: 92 additions & 0 deletions src/PrinceXMLPhp/Types/PdfProfile.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php

namespace PrinceXMLPhp\Types;

/**
* Class Profile
* Type-safe type for setting the pdf-profile
* @package PrinceXMLPhp
*/
class PdfProfile extends AbstractEnumType
{
const A1B = 'PDF/A-1b';
const A3B = 'PDF/A-3b';
const X1A2001 = 'PDF/X-1a:2001';
const X1A2003 = 'PDF/X-1a:2003';
const X32002 = 'PDF/X-3:2002';
const X32003 = 'PDF/X-3:2003';
const X4 = 'PDF/X-4';

/**
* @inheritDoc
*/
protected function getAllowedValues()
{
return [
self::A1B,
self::A3B,
self::X1A2001,
self::X1A2003,
self::X32002,
self::X32003,
self::X4
];
}

/**
* @return PdfProfile
*/
public static function createA1B()
{
return new self(self::A1B);
}

/**
* @return PdfProfile
*/
public static function createA3B()
{
return new self(self::A3B);
}

/**
* @return PdfProfile
*/
public static function createX1A2001()
{
return new self(self::X1A2001);
}

/**
* @return PdfProfile
*/
public static function createX1A2003()
{
return new self(self::X1A2003);
}

/**
* @return PdfProfile
*/
public static function createX32002()
{
return new self(self::X32002);
}

/**
* @return PdfProfile
*/
public static function createX32003()
{
return new self(self::X32003);
}

/**
* @return PdfProfile
*/
public static function createX4()
{
return new self(self::X4);
}

}