Skip to content

Instantly share code, notes, and snippets.

@aspose-cloud
Last active June 4, 2021 02:36
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 aspose-cloud/490a299a1c42789590fdea5fb026196d to your computer and use it in GitHub Desktop.
Save aspose-cloud/490a299a1c42789590fdea5fb026196d to your computer and use it in GitHub Desktop.
This Gist contains code snippets regarding processing Signature Fields in PDF documents
This Gist contains code snippets regarding processing Signature Fields in PDF documents.
protected $pdfApi;
// Get App key and App SID from https://dashboard.aspose.cloud/
$appSid = '';
$appKey = '';
$host = 'https://api.aspose.cloud/v3.0';
// configuration object
$this->config = new Configuration();
$this->config->setAppKey($appKey);
$this->config->setAppSid($appSid);
$this->config->setHost($host);
// create PdfApi instance
$this->pdfApi = new PdfApi(null, $this->config);
// name of input PDF document
$name = 'BlankWithSignature.pdf';
// upload file to cloud storage
$this->uploadFile($name);
$signatureFileName = '33226.p12';
$this->uploadFile($signatureFileName);
$folder = $this->tempFolder;
$signature = new Aspose\PDF\Model\Signature();
$signature->setAuthority('Nayyer Shahbaz');
$signature->setContact('nayyer.shahbaz@aspose.com');
$signature->setDate('08/01/2012 12:15:00.000 PM');
$signature->setFormFieldName('Signature1');
$signature->setLocation('Australia');
$signature->setPassword('sIikZSmz');
$signature->setRectangle(new Aspose\PDF\Model\Rectangle(['llx' => 100, 'lly' => 100, 'urx' => 0, 'ury' => 0]));
$signature->setSignaturePath($folder . '/' . $signatureFileName);
$signature->setSignatureType(Aspose\PDF\Model\SignatureType::PKCS7);
$signature->setVisible(true);
$signature->setShowProperties(false);
$field = new Aspose\PDF\Model\SignatureField();
$field->setPartialName('sign1');
// page index where signature field needs to be added
$field->setPageIndex(1);
$field->setSignature($signature);
// specify the rectangular region for the Signature field
$field->setRect(new Aspose\PDF\Model\Rectangle(['llx' => 100, 'lly' => 100, 'urx' => 160, 'ury' => 140]));
// call the API to add signature field
$response = $this->pdfApi->postSignatureField($name, $field, null, $this->tempFolder);
$this->assertEquals(200, $response->getCode());
protected $pdfApi;
// Get App key and App SID from https://dashboard.aspose.cloud/
$appSid = '';
$appKey = '';
$host = 'https://api.aspose.cloud/v3.0';
// configuration object
$this->config = new Configuration();
$this->config->setAppKey($appKey);
$this->config->setAppSid($appSid);
$this->config->setHost($host);
// create PdfApi instance
$this->pdfApi = new PdfApi(null, $this->config);
// name of input PDF document
$name = 'BlankWithSignature.pdf';
// upload PDF to cloud storage
$this->uploadFile($name);
// signature field to retrieve information
$fieldName = 'Signature1';
// call API to retrieve signature field details
$response = $this->pdfApi->getSignatureField($name, $fieldName, null, $this->tempFolder);
$this->assertEquals(200, $response->getCode());
protected $pdfApi;
// Get App key and App SID from https://dashboard.aspose.cloud/
$appSid = '';
$appKey = '';
$host = 'https://api.aspose.cloud/v3.0';
// configuration object
$this->config = new Configuration();
$this->config->setAppKey($appKey);
$this->config->setAppSid($appSid);
$this->config->setHost($host);
// create PdfApi instance
$this->pdfApi = new PdfApi(null, $this->config);
// name of input PDF document
$name = 'BlankWithSignature.pdf';
// upload the file to cloud storage
$this->uploadFile($name);
// page number in document
$pageNumber = 1;
// call API method to retrieve signature fields from document
$response = $this->pdfApi->getPageSignatureFields($name, $pageNumber, null, $this->tempFolder);
$this->assertEquals(200, $response->getCode());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment