I'm a first time poster and am brand new to your SDK, so I'm sorry if I'm doing something wrong here, but I'm stuck, and my code seems similar to other sets of code I've found on these forums, and I'm stumped as to why this isn't working. I'm hoping you can help me figure it out.
I'm capturing a signature from a device using that devices SDK, and I'm just trying to open the PDF, find a field that is basically a placeholder for the signature, append the image of the signature, delete the original field, and then write the new PDF out to a new file which I'll save back to my application's directory.
Here is the important part of my code:
Code: Select all
List<string> signatures = new List<string>();
doc = inst.OpenDocumentFromFile(localPath + "EISIGN_" + row.FileName,null,null,0,0);
uint pages = doc.Pages.Count;
int rotation = doc.Pages[0].Rotation;
if (doc.HasAcroForm)
{
List<IPXC_FormField> fields = new List<IPXC_FormField>();
fields.Add(doc.AcroForm.GetFieldByName("Signature1"));
foreach (IPXC_FormField field in fields)
{
if (field.FullName == "Signature1")
{
//Generate signature data/Capture Signature
DynamicCapture sign = new DynamicCapture();
SigCtl signature = new SigCtl();
signature.InputWho = row.PatName;
signature.InputWhy = row.ChartDisplayName;
signature.Licence = "XXXXXX";
DynamicCaptureResult result = new DynamicCaptureResult();
//Check signature capture result
result = sign.Capture(signature);
if (result == DynamicCaptureResult.DynCaptOK)
{
SigObj sigObj = new SigObj();
sigObj = (SigObj)signature.Signature;
PXC_Rect rect = field.Widget[0].get_Rect();
sigObj.RenderBitmap(localPath + "sig.png", (int)rect.left*2, (int)rect.bottom*2, "image/png", 1, 0x000000, 0xffffff, 10.0f, 10.0f, RBFlags.RenderOutputFilename | RBFlags.RenderColor32BPP | RBFlags.RenderEncodeData | RBFlags.RenderBackgroundTransparent);
try
{
IPXC_Annotation annot = field.Widget[0];
IPXC_Image image = doc.AddImageFromFile(localPath + "sig.png", 0 /*annot.Page.Number*/);
PXC_Matrix matrix = new PXC_Matrix();
matrix.a = rect.right - rect.left;
matrix.d = rect.bottom - rect.top;
matrix.e = rect.left;
matrix.f = rect.bottom;
IPXC_ContentCreator cc = doc.CreateContentCreator();
cc.ConcatCS(matrix);
cc.PlaceImage(image);
doc.AcroForm.DeleteField(field.FullName);
}
catch (Exception z)
{
File.AppendAllText(logPath, "\n" + aUX_Inst.FormatHRESULT(z.HResult));
}
File.Delete(localPath + "sig.png");
signatures.Add(signature.InputSignature);
}
else if (result == DynamicCaptureResult.DynCaptCancel)
{
documentViewer.Navigate(localPath + "EISIGN_" + row.FileName);
}
else if (result == DynamicCaptureResult.DynCaptPadError)
{
documentViewer.Navigate(localPath + "EISIGN_" + row.FileName);
MessageBox.Show("WACOM Device Not Found!", "Error", MessageBoxButtons.OK);
}
else if (result == DynamicCaptureResult.DynCaptNotLicensed)
{
documentViewer.Navigate(localPath + "EISIGN_" + row.FileName);
MessageBox.Show("WACOM Interface Not Licensed!", "Error", MessageBoxButtons.OK);
}
else
{
documentViewer.Navigate(localPath + "EISIGN_" + row.FileName);
MessageBox.Show("There Was An Error!", "Error", MessageBoxButtons.OK);
}
}
//COMMIT CHANGES TO FILE IN LOCAL CACHE
doc.WriteToFile(localPath + "sigDoc" + row.FileName);
doc.Close();