I'm trying to create a PDF Signature Field on a blank PDF using iText7 version 8.0.3
It seems that the .CreateSignature methods aren't there anymore, so I'm trying to figure out how do to this.
Can anyone help me out?
Here's what I was trying:
public async Task<FileStreamResult> DownloadPropertyList(LDSC_DownloadParams downloadParams)
{
Instance instance = await GetInstance(downloadParams.ImplementationId);
// Create a new PDF document
MemoryStream memoryStream = new MemoryStream();
PdfWriter writer = new PdfWriter(memoryStream);
writer.SetCloseStream(false);
PdfDocument pdf = new PdfDocument(writer);
Document document = new Document(pdf);
// Create a table with a column for each property attribute
Table table = new Table(UnitValue.CreatePercentArray(new float[] { 20, 20, 20, 10, 10, 20 }))
.UseAllAvailableWidth();
// Add headers to the table
table.AddHeaderCell("Property Name");
table.AddHeaderCell("Address");
table.AddHeaderCell("City");
table.AddHeaderCell("State");
table.AddHeaderCell("Zip Code");
table.AddHeaderCell("Contact");
// Iterate over ScreeningProperties and add rows to the table
foreach (var property in instance.ScreeningProperties)
{
table.AddCell(property.PropertyName ?? "");
table.AddCell(property.Address ?? "");
table.AddCell(property.City ?? "");
table.AddCell(property.State?.ToString() ?? "");
table.AddCell(property.ZipCode ?? "");
table.AddCell($"{property.ContactPerson ?? ""}\n{property.PhoneNumber ?? ""}");
}
// Add the table to the document
document.Add(table);
// Add signature field
PdfAcroForm form = PdfAcroForm.GetAcroForm(pdf, true);
PdfFormField signature = PdfFormField.CreateSignature(pdf, new Rectangle(100, 100, 200, 50));
signature.SetFieldName("Signature");
form.AddField(signature);
// Close the document
document.Close(); // This finalizes the document and writes it to the memory stream
// Prepare the memory stream to be returned
memoryStream.Position = 0;
// Return the FileStreamResult
// Adjust the file name as needed
return new FileStreamResult(memoryStream, "application/pdf")
{
FileDownloadName = "PropertyList.pdf"
};
}
The issue is that PdfFormField.CreateSignature no longer exists in 8.0.3 and I'm not sure how to do this.
Got it figured out - it can be generated like this: