Skip to content
This repository has been archived by the owner on Apr 11, 2024. It is now read-only.

Commit

Permalink
Add version information
Browse files Browse the repository at this point in the history
Users now have three ways to find out the dompdf version:

 - VERSION file in repo root
 - $dompdf->version, built on-the-fly from the VERSION file
 - the Producer field in the PDF metadata

The VERSION file depends on format string replacement using the `git
archive` command. If the format string isn't replaced dompdf will not
use the value in the file and will fall back to "dompdf" as the
version.
  • Loading branch information
bsweeney committed Oct 10, 2015
1 parent 1c7990c commit 5d80bca
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@
*.txt text
*.svg text

VERSION export-subst
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$Format:<%h>$
2 changes: 1 addition & 1 deletion lib/Cpdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -1228,7 +1228,7 @@ protected function o_info($id, $action, $options = '')
$this->objects[$id] = array(
't' => 'info',
'info' => array(
'Creator' => 'R and OS php pdf writer, http://www.ros.co.nz',
'Producer' => 'CPDF (dompdf)',
'CreationDate' => $date
)
);
Expand Down
2 changes: 1 addition & 1 deletion src/Adapter/CPDF.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ function __construct($paper = "letter", $orientation = "portrait", Dompdf $dompd
$dompdf->get_option("temp_dir")
);

$this->_pdf->addInfo("Creator", "DOMPDF");
$this->_pdf->addInfo("Producer", sprintf("%s + CPDF", $dompdf->version));
$time = substr_replace(date('YmdHisO'), '\'', -2, 0) . '\'';
$this->_pdf->addInfo("CreationDate", "D:$time");
$this->_pdf->addInfo("ModDate", "D:$time");
Expand Down
3 changes: 2 additions & 1 deletion src/Adapter/PDFLib.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ function __construct($paper = "letter", $orientation = "portrait", Dompdf $dompd
$this->_pdf->set_parameter("textformat", "utf8");
$this->_pdf->set_parameter("fontwarning", "false");

$this->_pdf->set_info("Creator", "DOMPDF");
// TODO: fetch PDFLib version information for the producer field
$this->_pdf->set_info("Producer", sprintf("%s + PDFLib", $dompdf->version));

// Silence pedantic warnings about missing TZ settings
$tz = @date_default_timezone_get();
Expand Down
36 changes: 35 additions & 1 deletion src/Dompdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@
*/
class Dompdf
{
/**
* Version string for dompdf
*
* @var string
*/
private $version = 'dompdf';

/**
* DomDocument representing the HTML document
*
Expand Down Expand Up @@ -252,6 +259,11 @@ class Dompdf
public function __construct()
{
$this->setOptions(new Options);

$versionFile = realpath(__DIR__ . '/../VERSION');
if (file_exists($versionFile) && ($version = file_get_contents($versionFile)) !== false && $version !== '$Format:<%h>$') {
$this->version = sprintf('dompdf %s', $version);
}

$this->localeStandard = sprintf('%.1f', 1.0) == '1.0';
$this->saveLocale();
Expand Down Expand Up @@ -954,7 +966,7 @@ public function set_option($key, $value)
$this->options->set($key, $value);
return $this;
}

/**
* @param array $options
* @return $this
Expand Down Expand Up @@ -1411,4 +1423,26 @@ public function getFontMetrics()
{
return $this->fontMetrics;
}

/**
* PHP5 overloaded getter
* Along with {@link Dompdf::__set()} __get() provides access to all
* properties directly. Typically __get() is not called directly outside
* of this class.
*
* @param string $prop
*
* @throws Exception
* @return mixed
*/
function __get($prop)
{
switch ($prop)
{
case 'version' :
return $this->version;
default:
throw new Exception( 'Invalid property: ' . $field );
}
}
}

0 comments on commit 5d80bca

Please sign in to comment.