Extract Image and Signature Information using Aspose.PDF for C++
Contents
[
Hide
]
Extracting Image from Signature Field
Aspose.PDF for C++ supports the feature to digitally sign the PDF files using the SignatureField class and while signing the document.
In order to extract signature information, we have introduced the ExtractImage method to the SignatureField class.
Please take a look at the following code snippet which demonstrates the steps to extract an image from the SignatureField object:
void SecuringAndSigning::ExtractingImageFromSignatureField() {
// String for path name.
String _dataDir("C:\\Samples\\");
auto pdfDocument = MakeObject<Document>(_dataDir + u"ExtractingImage.pdf");
int i = 0;
try {
for (auto& field : pdfDocument->get_Form()->get_Fields()) {
auto sf = System::DynamicCast<Aspose::Pdf::Forms::SignatureField>(field);
if (sf != nullptr) {
auto output = System::IO::File::OpenWrite(_dataDir + u"im" + i + u".jpeg");
auto tempStream = sf->ExtractImage();
tempStream->CopyTo(output);
output->Close();
}
}
}
catch (System::IO::IOException e) {
Console::WriteLine(e->get_Message());
}
}
Extract Signature Information
Aspose.PDF for C++ allows extracting signature information. For this, we have introduced the ExtractCertificate method to the SignatureField class.
Please take a look at the following code snippet which demonstrates the steps to extract the certificate from SignatureField object:
void SecuringAndSigning::ExtractSignatureInformation() {
String _dataDir("C:\\Samples\\");
String input = _dataDir + u"ExtractSignatureInfo.pdf";
auto pdfDocument = MakeObject<Document>(input);
for (auto& field : pdfDocument->get_Form()->get_Fields()) {
auto sf = System::DynamicCast<Aspose::Pdf::Forms::SignatureField>(field);
if (sf != nullptr) {
auto cerStream = sf->ExtractCertificate();
if (cerStream != nullptr) {
auto outStream = System::IO::File::OpenWrite(_dataDir + u"targetFile.cer");
cerStream->CopyTo(outStream);
outStream->Close();
}
}
}
}