Spot colors: Sonderfarben
AddSpotColor($name, $c, $m, $y, $k) legt eine Sonderfarbe mit ihren CMYK-Ersatzwerten an. SetDrawSpotColor(), SetFillSpotColor() und SetTextSpotColor() wählen sie aus, auf Wunsch mit einem Tonwert in Prozent. Druckereien verlangen das für Hausfarben, die als eigene Druckfarbe laufen.
| Nummer | 89 |
|---|---|
| Originaltitel | Spot colors |
| Autor | Olivier |
| Lizenz | FPDF (frei, auch für kommerzielle Nutzung) |
| Quelle | fpdf.org, Skript 89 (englisch, mit Archiv zum Herunterladen) |
Quelltext
Speichern Sie die Klasse in einer eigenen Datei neben fpdf.php. Kommentare und Bezeichner stehen wie im Original auf Englisch.
PHP
<?php
require('fpdf.php');
class PDF_SpotColor extends FPDF
{
protected $SpotColors = array();
function AddSpotColor($name, $c, $m, $y, $k)
{
if(!isset($this->SpotColors[$name]))
{
$i = count($this->SpotColors)+1;
$this->SpotColors[$name] = array('i'=>$i, 'c'=>$c, 'm'=>$m, 'y'=>$y, 'k'=>$k);
}
}
function SetDrawSpotColor($name, $tint=100)
{
if(!isset($this->SpotColors[$name]))
$this->Error('Undefined spot color: '.$name);
$this->DrawColor = sprintf('/CS%d CS %.3F SCN', $this->SpotColors[$name]['i'], $tint/100);
if($this->page>0)
$this->_out($this->DrawColor);
}
function SetFillSpotColor($name, $tint=100)
{
if(!isset($this->SpotColors[$name]))
$this->Error('Undefined spot color: '.$name);
$this->FillColor = sprintf('/CS%d cs %.3F scn', $this->SpotColors[$name]['i'], $tint/100);
$this->ColorFlag = ($this->FillColor!=$this->TextColor);
if($this->page>0)
$this->_out($this->FillColor);
}
function SetTextSpotColor($name, $tint=100)
{
if(!isset($this->SpotColors[$name]))
$this->Error('Undefined spot color: '.$name);
$this->TextColor = sprintf('/CS%d cs %.3F scn', $this->SpotColors[$name]['i'], $tint/100);
$this->ColorFlag = ($this->FillColor!=$this->TextColor);
}
function _putspotcolors()
{
foreach($this->SpotColors as $name=>$color)
{
$this->_newobj();
$this->_put('[/Separation /'.str_replace(' ','#20',$name));
$this->_put('/DeviceCMYK <<');
$this->_put('/Range [0 1 0 1 0 1 0 1] /C0 [0 0 0 0] ');
$this->_put(sprintf('/C1 [%.3F %.3F %.3F %.3F] ',$color['c']/100,$color['m']/100,$color['y']/100,$color['k']/100));
$this->_put('/FunctionType 2 /Domain [0 1] /N 1>>]');
$this->_put('endobj');
$this->SpotColors[$name]['n'] = $this->n;
}
}
function _putresourcedict()
{
parent::_putresourcedict();
$this->_put('/ColorSpace <<');
foreach($this->SpotColors as $color)
$this->_put('/CS'.$color['i'].' '.$color['n'].' 0 R');
$this->_put('>>');
}
function _putresources()
{
$this->_putspotcolors();
parent::_putresources();
}
}
?>Beispiel
So wird die Erweiterung aufgerufen:
PHP
<?php
require('spotcolor.php');
$pdf = new PDF_SpotColor();
$pdf->AddSpotColor('PANTONE 145 CVC', 0, 42, 100, 25);
$pdf->AddPage();
$pdf->SetFillSpotColor('PANTONE 145 CVC');
$pdf->Rect(80, 40, 50, 50, 'F');
$pdf->Output();
?>
Einbau
Add-ons werden nicht installiert, sondern eingebunden: Datei neben fpdf.php legen, mit require laden und die eigene Klasse von der Klasse des Add-ons ableiten. Brauchen Sie mehrere Add-ons, leiten Sie sie in einer Kette voneinander ab. Mehr dazu unter Installation und in der FAQ.