Skip to content

Instantly share code, notes, and snippets.

@Ravenna
Created January 10, 2019 23:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ravenna/13e2bb28a2fd56c85c9c53edd0ad4622 to your computer and use it in GitHub Desktop.
Save Ravenna/13e2bb28a2fd56c85c9c53edd0ad4622 to your computer and use it in GitHub Desktop.
<?php
require 'vendor/autoload.php';
$writer = new SetaPDF_Core_Writer_Http('output.pdf', true);
$document = SetaPDF_Core_Document::loadByFilename('test.pdf', $writer);
$formFiller = new SetaPDF_FormFiller($document);
$fields = $formFiller->getFields();
$stamper = new SetaPDF_Stamper($document);
// Get Post Data
$name = $_POST["name"];
$email = $_POST["email"];
$signature = $_POST["base64"];
$signature = base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $signature));
// Set fields
$fields['NAME']->setValue($name); // add some randomness
$fields['EMAIL']->setValue($email);
// Stamp Image
$image = SetaPDF_Core_Image::getByPath('signature.png');
$imageStamp = new SetaPDF_Stamper_Stamp_Image($image);
$stamp = new SetaPDF_Stamper_Stamp_Image($image);
// Set Signature
$stamper->addStamp($stamp, array(
'position' => SetaPDF_Stamper::POSITION_LEFT_BOTTOM,
'translateX' => 0,
'translateY' => 10,
));
$stamper->stamp();
$document->save()->finish();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment