Hello, I tried to put two signatures on a single pdf
but
always the last is valid
in the others sign i get the following error when I open the PDF with Adobe
SignDict/Contents contains illegal data
this is my code i use android version
private boolean firmaPDF(android.graphics.Bitmap bmpCanvas )
{
try
{
int scaledW= bmpCanvas.getWidth() / 2;
int scaledH= bmpCanvas.getHeight() / 2;
Bitmap bmp = Bitmap.createScaledBitmap(bmpCanvas, scaledW, scaledH, true);
Resources res = getResources();
//pdf based
InputStream is = res.openRawResource(R.raw.pdftron);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int reads = is.read();
while (reads != -1) {
baos.write(reads);
reads = is.read();
}
// Add an StdSignatureHandler instance to PDFDoc, making sure to keep track of it using the ID returned.
long sigHandlerId = doc.addStdSignatureHandler(baos.toByteArray(), "password");
Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat ("yyyyMMddHHmmss");
//I have several fields to sign
strFieldFirma ="firma_1_"+myExternalCounter;
//temporary outname pdf
outFile = getNomeFoglioFirme();
Field sigField = doc.getField(strFieldFirma);
Widget widgetAnnot = new Widget(sigField.getSDFObj());
// Widget w2 = Widget.create(doc.getSDFDoc(), new pdftron.PDF.Rect(0, 0,bmp.getWidth(), bmp.getHeight()), sigField);
// Tell PDFNet to use the SignatureHandler created to sign the new signature form field.
Obj sigDict = sigField.useSignatureHandler(sigHandlerId);
// Add more information to the signature dictionary
sigDict.putName("SubFilter", "adbe.pkcs7.detached");
sigDict.putString("Name", "PDFTron");
sigDict.putString("Location", "Vancouver, BC");
sigDict.putString("Reason", "Document verification.");
// Add the signature appearance
ElementWriter apWriter = new ElementWriter();
ElementBuilder apBuilder = new ElementBuilder();
apWriter.begin(doc);
Image sigImg = Image.create(doc, bmp);
double w = sigImg.getImageWidth(), h = sigImg.getImageHeight();
Element apElement = apBuilder.createImage(sigImg, 0, 0, w, h);
// Element apElement = apBuilder.createImage(sigImg, new Matrix2D(sigImg.getImageWidth(), 0, 0, sigImg.getImageHeight(), 50, 350));
apWriter.writePlacedElement(apElement);
Obj apObj = apWriter.end();
apObj.putRect("BBox", 0, 0, w, h);
apObj.putName("Subtype", "Form");
apObj.putName("Type", "XObject");
apWriter.begin(doc);
apElement = apBuilder.createForm(apObj);
apWriter.writePlacedElement(apElement);
apObj = apWriter.end();
apObj.putRect("BBox", 0, 0, w, h);
apObj.putName("Subtype", "Form");
apObj.putName("Type", "XObject");
widgetAnnot.setAppearance(apObj);
widgetAnnot.refreshAppearance();
apWriter.begin(doc);
Image img = Image.create(doc.getSDFDoc(), bmp);
Element element = apBuilder.createImage(img, new Matrix2D(200, 0, 0, 250, 50, 500));
apWriter.writePlacedElement(element);
apWriter.end();
// Save the PDFDoc. Once the method below is called, PDFNet will also sign the document using the information
// provided.
doc.save(outFile, 0, null);
return true;
}
catch(Exception ex)
{
System.err.println(ex.getMessage());
ex.printStackTrace(System.err);
return false;
}
finally {
}
}