… here’s some sample code from a project a while ago where I needed to fill out a form and then put a stamp on it. Not exactly what you are talking about, but an example of taking a form with some pre-defined fields, adding values to those fields, adding a couple of time stamps and then saving the whole thing as a PDF. (This is a just a piece of the method in the model.)
$document = \SetaPDF_Core_Document::loadByFilename(Yii::getAlias('@app/resources/'.$this->name));
$formFiller = new \SetaPDF_FormFiller($document);
$fields = $formFiller->getFields();
$fieldNames = $fields->getNames();
Yii::info('form fields '.print_r($fieldNames,true),__METHOD__);
$formFiller->setRemoveXfaInformation(true);
$maps = json_decode($this->map);
foreach ($maps->accountInfo as $k=>$v) if ($v and isset($this->accountInfo->$v)) $fields[$k]->setValue($this->accountInfo->$v);
foreach ($maps->form as $k=>$v) if ($v and isset($this->form->$v)) $fields[$k]->setValue($this->fisc->$v);
$writer = new \SetaPDF_Core_Writer_Http($date->format('Y-m-d H-i-s ').$this->accountInfo->id.' form.pdf',true);
$document->setWriter($writer);
$stamper = new \SetaPDF_Stamper($document);
$pages = $document->getCatalog()->getPages();
if ($sign) {
foreach ($fieldNames as $name) {
if (!in_array($name,['SignaturePlaceholder','euShortDate'])) $fields->get($name)->flatten();
}
$fields->get('SignaturePlaceholder')->setValue('{Signature}');
for ($i=5;$i>2;$i--) $pages->deletePage($i);
}
else {
$intro = $pages->create('letter','portrait',false);
$pages->prepend($intro);
$outro = $pages->create('letter','portrait',false);
$pages->append($outro);
$stamp = new \SetaPDF_Stamper_Stamp_Pdf(
'pdfs/intro.pdf', 1, \SetaPDF_Core_PageBoundaries::CROP_BOX
);
$stamper->addStamp(
$stamp,
\SetaPDF_Stamper::POSITION_LEFT_BOTTOM,
1
);
$stamp = new \SetaPDF_Stamper_Stamp_Pdf(
'pdfs/outro.pdf', 1, \SetaPDF_Core_PageBoundaries::CROP_BOX
);
$stamper->addStamp(
$stamp,
\SetaPDF_Stamper::POSITION_LEFT_BOTTOM,
'last'
);
}
$font = \SetaPDF_Core_Font_Standard_Helvetica::create($document);;
$stamp = new \SetaPDF_Stamper_Stamp_Text($font, 8);
$stamp->setTextColor([0, 0, 0]);
$stamp->setText(trim((string)$this->accountInfo->id).' F52 '.$date->format('Ymd'));
$stamper->addStamp(
$stamp,
\SetaPDF_Stamper::POSITION_LEFT_BOTTOM,
2,
5,
30,
0
);
$font = new \SetaPDF_Core_Font_TrueType_Subset($document,'fonts/Code39r.ttf');
$stamp = new \SetaPDF_Stamper_Stamp_Text($font, 24);
$stamp->setTextColor([0, 0, 0]);
$stamp->setAlign(\SetaPDF_Core_Text::ALIGN_CENTER);
$stamp->setText(trim((string)$this->accountInfo->LOOKUP_ID).' F52 '.$date->format('Ymd'));
$stamper->addStamp(
$stamp,
\SetaPDF_Stamper::POSITION_LEFT_BOTTOM,
2,
5,
5
);
$font = \SetaPDF_Core_Font_Standard_Helvetica::create($document);
if (!$sign) {
$stamp = new \SetaPDF_Stamper_Stamp_Text($font, 12);
$stamp->setTextColor([1, 0, 0]);
$stamp->setAlign(\SetaPDF_Core_Text::ALIGN_CENTER);
$stamp->setText('Please Return This Page');
$stamper->addStamp(
$stamp,
\SetaPDF_Stamper::POSITION_RIGHT_BOTTOM,
[2,3],
0,
100,
-90
);
}
$font = \SetaPDF_Core_Font_Standard_HelveticaBold::create($document);
$stamp = new \SetaPDF_Stamper_Stamp_Text($font, 10);
$stamp->setTextColor([0, 0, 0]);
$stamp->setAlign(\SetaPDF_Core_Text::ALIGN_LEFT);
$stamp->setText('Secure Upload: ');
$stamper->addStamp(
$stamp,
\SetaPDF_Stamper::POSITION_LEFT_BOTTOM,
5,
30,
40,
);
$phone = new \SetaPDF_Stamper_Stamp_Text($font, 10);
$phone->setTextColor([0, 0, 0]);
$phone->setAlign(\SetaPDF_Core_Text::ALIGN_LEFT);
$phone->setText(preg_replace('/(\d{3})(\d{3})(\d{4})/','($1) $2-$3',$this->accountInfo->office->telephone));
$stamper->addStamp(
$phone,
\SetaPDF_Stamper::POSITION_LEFT_BOTTOM,
5,
340,
110,
);
// stamp the document
$stamper->stamp();
if ($sign) return $document;
$writer = new \SetaPDF_Core_Writer_Http($date->format('Y-m-d H-i-s ').$this->accountInfo->id.' form.pdf',true);
$document->setWriter($writer);
$document->save()->finish();