Created
March 25, 2024 16:24
-
-
Save bjoerntx/4dd226e241fd0d899e8336431584710f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[HttpPost] | |
[Route("CustomSign")] | |
public string CustomSign([FromBody] SignatureData signatureData) | |
{ | |
byte[] pdfBytes; | |
using (var tx = new ServerTextControl()) { | |
tx.Create(); | |
tx.Load("App_Data/template.tx", StreamType.InternalUnicodeFormat); | |
// load the signature image into the signature fields | |
foreach (var box in signatureData.SignatureBoxes) { | |
foreach (SignatureField field in tx.SignatureFields) { | |
if (field.Name == box.Name) { | |
var stamp = Convert.FromBase64String(signatureData.SignatureImage); | |
using (var ms = new MemoryStream(stamp, 0, stamp.Length, false, true)) { | |
field.Image = new SignatureImage(ms); | |
} | |
} | |
} | |
} | |
// fill the form fields with the data | |
foreach (TXTextControl.FormField formField in tx.FormFields) { | |
foreach (var dataField in signatureData.FormFields) { | |
if (dataField.Name == formField.Name) { | |
formField.Text = dataField.Value; | |
break; | |
} | |
} | |
} | |
FlattenFormFields(tx); | |
tx.Save(out pdfBytes, BinaryStreamType.AdobePDF); | |
} | |
return Convert.ToBase64String(pdfBytes); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment