[
https://issues.apache.org/jira/browse/PDFBOX-4312?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16850887#comment-16850887
]
bal commented on PDFBOX-4312:
-----------------------------
i want visual representation of the signature. i want to show the the signature
properties values i.e signer name,reason in the blankbox. i have tried with
below code but getting null pointer exception . please let me know where i am
wrong
PDAcroForm acroForm = new PDAcroForm(signedDoc);
signedDoc.getDocumentCatalog().setAcroForm(acroForm);
signedDoc.getDocumentCatalog().getCOSObject().setNeedToBeUpdate(true);
PDSignatureField signatureField = new PDSignatureField(acroForm);
List<PDField> acroFormFields = new List<PDField>();
acroForm.getCOSObject().setDirect(true);
acroForm.getCOSObject().setNeedToBeUpdate(true);
acroFormFields.Add(signatureField);
signatureField.getCOSObject().setNeedToBeUpdate(true);
PDAnnotationWidget Widget = new PDAnnotationWidget();
Widget.getCOSObject().setNeedToBeUpdate(true);
Widget.setRectangle(pdRectangle);
Widget.setPage(page);
PDStream pdfstream = new PDStream(signedDoc);
pdfstream.getCOSObject().setNeedToBeUpdate(true);
PDXObjectForm form = new PDXObjectForm(pdfstream);
form.getCOSObject().setNeedToBeUpdate(true);
PDResources resources = new PDResources();
resources.getCOSObject().setNeedToBeUpdate(true);
PDFont font = PDType1Font.HELVETICA;
resources.addFont(font);
form.setResources(resources);
form.setFormType(1);
PDRectangle bbox = new PDRectangle(pdRectangle.getWidth(),
pdRectangle.getHeight());
float height = bbox.getHeight();
form.setBBox(pdRectangle);
PDAppearanceDictionary appearanceDictionary = new
PDAppearanceDictionary(signedDoc.getDocumentCatalog().getCOSDictionary());
appearanceDictionary.getCOSObject().setDirect(true);
appearanceDictionary.getCOSObject().setNeedToBeUpdate(true);
PDAppearanceStream appearanceStream = new
PDAppearanceStream(form.getCOSStream());
appearanceStream.getCOSObject().setNeedToBeUpdate(true);
appearanceDictionary.setNormalAppearance(appearanceStream);
Widget.setAppearance(appearanceDictionary);
try
{
PDPageContentStream pagecontentStream = new PDPageContentStream(signedDoc,
page, true, false);
pagecontentStream.setNonStrokingColor(java.awt.Color.black);
pagecontentStream.addRect(x, y, sigWidth, sigheight);
int windingRule = PathIterator.WIND_NON_ZERO;
pagecontentStream.fill(windingRule);
PDXObjectImage imgobj = null;
imgobj = new PDJpeg(signedDoc, new FileInputStream(tickImagePath));
pagecontentStream.drawImage(imgobj, x, y);
pagecontentStream.saveGraphicsState();
pagecontentStream.restoreGraphicsState();
float fontSize = 8;
float leading = fontSize * 1.0f;
pagecontentStream.beginText();
if (!string.IsNullOrEmpty(name))
{
pagecontentStream.drawString("signed By:");
pagecontentStream.drawString("Name:" + name);
}
if (!string.IsNullOrEmpty(location))
pagecontentStream.drawString("Location:" + location);
if (!string.IsNullOrEmpty(reason))
pagecontentStream.drawString("Reason:" + reason);
pagecontentStream.endText();
pagecontentStream.close();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
signedDoc.save(baos);
return new ByteArrayInputStream(baos.toByteArray());
}
> Signature is not getting inserted into 00000 area
> -------------------------------------------------
>
> Key: PDFBOX-4312
> URL: https://issues.apache.org/jira/browse/PDFBOX-4312
> Project: PDFBox
> Issue Type: Bug
> Components: .NET, PDModel, Signing
> Affects Versions: 1.8.9, 1.8.15
> Reporter: bal
> Assignee: Tilman Hausherr
> Priority: Major
> Fix For: 1.8.17
>
> Attachments: image-2019-05-14-16-27-40-794.png
>
>
> Hi ,
> I want to sign pdf using signature in pkcs 7 format . I am converting pkcs 7
> signature to byte array using Convert.FromBase64String method in .net . I am
> passing this byte array to sign method in signature interface which gets
> called after calling saveincremental. My byte array is inserting proper but
> the name of which signature is not shown when i open pdf. May be my byte
> conversion may not proper or something else i am doing wrong. please let me
> know.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]