[
https://issues.apache.org/jira/browse/PDFBOX-4556?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16873165#comment-16873165
]
bal commented on PDFBOX-4556:
-----------------------------
hi , please find the attached pdfs one showing the image and another not
showing when i return the template as inputstream and setting it to
signatureOptions.setVisualSignature(inputstream of pdf template). i want to
show the image and the static appearence of the contents on the inserted pdfbox
in the pdf.But current scenario my image and the inserted pdfbox are on
different locations. please find the below code i am using. how to draw an
image without the use of the pagecontentstream ? is it possible?
code .....
PDDocument doc = new PDDocument();
PDPage page = new
PDPage(((PDPage)(signedDocument.getDocumentCatalog().getAllPages().get(0))).findMediaBox());
//PDPage page = new PDPage();
doc.addPage(page);
float x = (float)xCo_ordinates;
float y = (float)yCo_ordinates;
float sigWidth = (float)signatureWidth;
float sigheight = (float)signatureHeight;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PDAcroForm acroForm = new PDAcroForm(doc);
doc.getDocumentCatalog().setAcroForm(acroForm);
doc.getDocumentCatalog().getCOSObject().setNeedToBeUpdate(true);
PDSignatureField signatureField = new PDSignatureField(acroForm);
acroForm.getFields().add(signatureField);
List acroFormFields = acroForm.getFields();
acroForm.setFields(acroFormFields);
acroForm.getCOSObject().setDirect(true);
acroForm.getCOSObject().setNeedToBeUpdate(true);
PDAnnotationWidget widget = signatureField.getWidget();
widget.getCOSObject().setNeedToBeUpdate(true);
widget.setRectangle(pdRectangle);
widget.setPage(page);
PDStream pdfstream = new PDStream(doc);
pdfstream.getCOSObject().setNeedToBeUpdate(true);
PDXObjectForm form = new PDXObjectForm(pdfstream);
form.getCOSObject().setNeedToBeUpdate(true);
PDFont font = PDType1Font.HELVETICA;
PDResources resources = new PDResources();
resources.addFont(font);
Map pageFonts = resources.getFonts();
resources.setFonts(pageFonts);
resources.getCOSObject().setNeedToBeUpdate(true);
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();
appearanceDictionary.getCOSObject().setDirect(true);
appearanceDictionary.getCOSObject().setNeedToBeUpdate(true);
PDAppearanceStream appearanceStream = new
PDAppearanceStream(form.getCOSStream());
appearanceStream.getCOSObject().setNeedToBeUpdate(true);
appearanceDictionary.setNormalAppearance(appearanceStream);
PDXObjectImage imgxobj = null;
imagefile = new java.io.File(tickImagePath);
BufferedImage bufferedImage = null;
bufferedImage = ImageIO.read(imagefile);
imgxobj = new PDPixelMap(doc, bufferedImage);
int imgHeight = imgxobj.getHeight();
int imgWidth = imgxobj.getWidth();
resources.addFont(font, "F0"); // exact key
PDXObject xobj = imgxobj;
OutputStream os = form.getCOSStream().createFilteredStream();
os.write(Encoding.UTF8.GetBytes("0 0 0 rg\n" +
"150 150 150 150 re\n" +
"f\n" +
"q\n" + "" + imgHeight + " 0 0 " + imgWidth + " 0 0 cm\n" +
" /Im0 Do\n" +
"Q\n" +
"q\n" +
"Q\n" +
"/F0 10 Tf\n" +
"BT\n" +
" (signed By:) Tj\n" +
" (Name:name) Tj\n" +
" (Location:location) Tj\n" +
" (Reason:reason) Tj\n" +
"ET"));
os.close();
//resources.addXObject(xobj, "Im"); // just prefix
resources.addXObject(new PDJpeg(doc, new FileInputStream(tickImagePath)),
"Im");
widget.setAppearance(appearanceDictionary);
try
{
if (false)
{
PDPageContentStream pagecontentStream = new PDPageContentStream(doc, page,
true, false);
pagecontentStream.setNonStrokingColor(java.awt.Color.pink);
pagecontentStream.addRect(x, y, sigWidth, sigheight);
int windingRule = PathIterator.WIND_NON_ZERO;
pagecontentStream.drawImage(imgxobj, 150, 150);
pagecontentStream.saveGraphicsState();
pagecontentStream.restoreGraphicsState();
float fontSize = 8;
float leading = fontSize * 1.0f;
pagecontentStream.setFont(font, leading);
pagecontentStream.beginText();
pagecontentStream.moveTextPositionByAmount(155, 590);
{
pagecontentStream.drawString("Digitally signed By:");
pagecontentStream.drawString("Nname:");
}
{
pagecontentStream.drawString("Lnocation:");
}
{
pagecontentStream.drawString("Rneason:");
}
pagecontentStream.endText();
pagecontentStream.close();
}
}
catch (System.Exception ex)
{
ex.StackTrace.ToString();
}
List annotations = new ArrayList();
annotations.add(widget);
page.setAnnotations(annotations);
doc.save(baos);
doc.close();
return new ByteArrayInputStream(baos.toByteArray());
> how the visual representation of the signature is achieved
> ------------------------------------------------------------
>
> Key: PDFBOX-4556
> URL: https://issues.apache.org/jira/browse/PDFBOX-4556
> Project: PDFBox
> Issue Type: Wish
> Components: .NET
> Affects Versions: 1.8.16
> Reporter: bal
> Priority: Major
> Attachments: as_TobeSigned.pdf, pdfImage-modified-by-tilman.pdf,
> pdfImage.pdf
>
>
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]