We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Place Adobe PDF signature field in compiled template

Hi,

we are currently using Aspose.Words for Java and Aspose.Words for JasperReports to create dynamic reports in our web application.

I wanted to ask this: is there any way to insert in the jxml template we use to create the final report a field to be recognized as a valid signature field by Adobe Acrobat?

In this way, then, the PDF generated could be digitally signed directly without need to manually insert signature fields.

Hi Matteo,


Thanks for your inquiry. Please accept my apologies for late response.

Aspose.Words for JasperReport do not export jrxml into Pdf file format. Please read features of Aspose.Words for JasperReports from here:
http://www.aspose.com/docs/display/wordsjasperreports/Feature+Tour

In your case, you first need to export Jrxml file into Doc/Docx by using Aspose.Words for JasperReports. Once you have Doc/Docx file, you can use Aspose.Words for Java to create Digital Signed PDF document.

Unfortunately, you can not create digital signed pdf at the moment by using Aspose.Words for Java. We had already logged this issue as WORDSJAVA-542. I am in communication with our development team and I will update you as soon as I have more information about this issue.

We apologize for your inconvenience.

Hi,


I know some time has passed since I originally posted this support request.

However, I would like to elaborate a bit to give you some more details about what we would like to achieve.

Right now, we are using Aspose.Words for JasperReports to create .doc files from .jrxml templates, and then those .doc files are converted on-the-fly to .pdf files using Aspose.Words for Java.

A customer of us uses the generated .pdf file, adding a number of Signature Fields following the procedure described in the attached document.

Would it be possible in some way (perhaps using Aspose.Pdf for Java?) to automate the process?

I was thinking something like this, if at all possible:
- the .jrxml template is compiled into a .doc file -> Aspose.Words for JasperReports
- the .doc file is converted to .pdf file -> Aspose.Words for Java
- the resulting .pdf file is opened and a digital signature field is added -> Aspose.Pdf for Java (?)

I am also open to other suggestions on how to achieve this result.

I would like to underline, though, that we are not trying to directly sign the generated .pdf file, we just need to add one or more signature fields in it: it will be then up to this customer of us to use their own certificates to do the signing.

Thanks in advance for your help.
Hi Matteo,

Thanks for your inquiry.

Unfortunately, Aspose.Words does not support the requested feature. Your query is more related to Aspose.Pdf component. I am moving this thread to Aspose.Total forum. My colleagues from Aspose.Pdf team will reply you shortly.

Hi Matteo,

Thanks for your inquiry. You can easily add a signature field to an existing PDF document using Aspose.Pdf Kit for java. Please check following documentation link for the details/code snippet. Hopefully it will serve the purpose.

Please feel free to contact us for any further assistance.

Best Regards,

Hi,

thanks for your prompt answer.

I’ve checked the docs, and it would seem that Aspose.Pdf.Kit is what we need. As far as I can tell from the example, it requires the exact coordinates of where to place the fields, wouldn’t it be possibile to use some kind of placeholder text like “SIGNATURE” to be the replaced by the signature field?

Thanks again for your help.

Hi Matteo,


I am afraid currently Aspose.Pdf.Kit for Java does not support the feature of placeholders so that they can be replaced with form fields over the run-time. Furthermore, the current release version of Aspose.Pdf.Kit for Java also does not support the feature to search particular text string inside the PDF document. However currently we are working on testing the new release version of Aspose.Pdf for Java which provides the capability to create as well as manipulate existing PDF documents. It also offers the feature to search particular text string and get its coordinates information.

So once we have the coordinates information, we can replace the current text string with blank characters and place Signature field over that location. We hope to release the new autoported (the code base is ported from Aspose.Pdf for .NET to Java platform) release version of Aspose.Pdf for Java within current month.

We are sorry for this inconvenience.

Hi,


I just noticed this warning in the Aspose.pdf.kit for Java page:

NOTE: Aspose.Pdf.Kit for Java has been merged into Aspose.Pdf for Java under com.aspose.pdf.facades package. The separate release of Aspose.Pdf.Kit for Java will be discontinued in Q3-2013.

does it mean that, if we purchase a license for Aspose.Pdf for Java, we’ll get Aspose.Pdf.Kit too? And would that be right now or do we have to wait for Q3-2013?

Hi Matteo,


Thanks for your patience.

Please note that an autoported MergedAPI releas of Aspsoe.Pdf for Java 4.0.0 is published. So far we have not changed the pricing of this component and if you buy the license, you will be able to take benefit of Aspose.Pdf.Kit for Java package under this component. However if there is any change in the product pricing, we will let you know.

So please download the latest product copy and start using the new release API. Before you buy the license, you may also request a 30 days temporary license. For further details, please visit Get a temporary license
mtassinari:
Hi,

thanks for your prompt answer.

I've checked the docs, and it would seem that Aspose.Pdf.Kit is what we need. As far as I can tell from the example, it requires the exact coordinates of where to place the fields, wouldn't it be possibile to use some kind of placeholder text like "__SIGNATURE__" to be the replaced by the signature field?

Thanks again for your help.

Quoting myself to ask if this feature is going to be implemented in Aspose.Pdf fo Java and, if so, if it is possible to know when it'll be available.

mtassinari:
I’ve checked the docs, and it would seem that Aspose.Pdf.Kit is what we need. As far as I can tell from the example, it requires the exact coordinates of where to place the fields, wouldn’t it be possibile to use some kind of placeholder text like “SIGNATURE” to be the replaced by the signature field?

Hi Matteo,

Thanks for your patience.

I am pleased to share that new autoported Aspose.Pdf for Java supports the feature to search particular text string and get its coordinates. Then you can place Signature field on that particular location and replace the placeholder text with blank characters. For further information, please visit

So I recommend you to please try using the latest release of Aspose.Pdf for Java 4.0.0 to accomplish your requirements. In the event of any further query, please feel free to contact.

It seems exactly what we are looking for, thanks!


However, I’ve read the docs, and I do not understand clearly, I see I can get X-Y coordinates of the searched text fragment, but how can I know the page number where the fragment has been found? Do I have to make a loop which searches only one page at a time?

Thanks again.

Hi Matteo,


When searching particular string through all pages of PDF document, you can get the page number information on which the particular string occurs using textFragment.Page.Number property. Something similar to

Console.WriteLine("Page : {0} ",
textFragment.Page.Number);
codewarior:
Hi Matteo,

When searching particular string through all pages of PDF document, you can get the page number information on which the particular string occurs using textFragment.Page.Number property. Something similar to

Console.WriteLine("Page : {0} ", textFragment.Page.Number);

It would seem that the class TextFragment in Aspose.Pdf for Java does not have any property like that, nor can I find any getter which would return the current page in which the text fragment itself is located.
mtassinari:
It would seem that the class TextFragment in Aspose.Pdf for Java does not have any property like that, nor can I find any getter which would return the current page in which the text fragment itself is located.
Hi Matteo,

My apologies for this confusion.

I shared the code snippet related to Aspose.Pdf for .NET and I am afraid the current release of Aspose.Pdf for Java does not include a method which can return the page number on which a particular text string exists. However as a workaround, you may consider iterating through each page of PDF file and search the text string. When traversing through individual page, you will have the track of page number on which the TextFragment exists.
codewarior:
I shared the code snippet related to Aspose.Pdf for .NET and I am afraid the current release of Aspose.Pdf for Java does not include a method which can return the page number on which a particular text string exists. However as a workaround, you may consider iterating through each page of PDF file and search the text string. When traversing through individual page, you will have the track of page number on which the TextFragment exists.

That is exactly what I have done, I created a loop over all the pages of the pdf document, and for each page I use a TextFragmentAbsorber to search for my placeholder. Here is the method I created:

public static com.aspose.pdf.Document placeSignatureFields(com.aspose.words.Document doc) throws Exception {
// salvo su byte array temporaneo
ByteArrayOutputStream baos = new ByteArrayOutputStream();
doc.save(baos, SaveFormat.PDF);

// ricarico come documento pdf
com.aspose.pdf.Document pdf = new com.aspose.pdf.Document(new ByteArrayInputStream(baos.toByteArray()));

// pagine e form del pdf
PageCollection pages = pdf.getPages();
int num = pages.size();
Form form = pdf.getForm();

for (int i = 1; i <= num; ++i) {
// oggetto che effettua la ricerca
TextFragmentAbsorber tfa = new TextFragmentAbsorber("____________________");

// cerco nella pagina corrente
Page page = pages.get_Item(i);
tfa.visit(page);

// prelevo i frammenti di testo corrispondenti
TextFragmentCollection tfc = tfa.getTextFragments();
for (int j = 1; j <= tfc.size(); ++j) {
// ne leggo la posizione
Position p = tfc.get_Item(j).getPosition();

// prelevo coordinate X-Y
double x1 = p.getXIndent();
double y1 = p.getYIndent();
double x2 = x1 + 110.0;
double y2 = y1 + 30.0;

// le "circondo" con un campo di firma
SignatureField sign = new SignatureField(
page,
new Rectangle(x1, y1, x2, y2)
);
sign.setPartialName("signature_" + i + "_" + j);

// lo aggiungo
form.add(sign, i);
}
}

return pdf;
}

However, wouldn't it be faster if I could search the whole document at once instead of looping through the pages? It should'n be hard to add a method that would return the page in which the TextFragment is placed, and from that, I think I can obtain the page number somehow, can't I?

Hi Matteo,


As shared in my earlier post where I have specified the property which can be used to get page number information related to TextFragment, we plan to introduce similar functionality in Aspose.Pdf for Java. I have logged this problem as PDFNEWJAVA-33510 in our issue tracking system. Currently I cannot confirm the accurate build, but hopefully in next release versions, this capability will become available. We are sorry for this inconvenience.

Hi Matteo,


Thanks for your patience in reference to above logged issue PDFNEWJAVA-33510, you issue has been fixed in result of some other fix. Now the required feature is available in Aspose.Pdf for Java i.e. textFragment.getPage().getNumber(). You may download and try latest version of Aspose.Pdf for Java, it wil resolve the issue.

//open document<o:p></o:p>

com.aspose.pdf.Document pdfDocument = new com.aspose.pdf.Document("input.pdf");

//create TextAbsorber object to find all instances of the input search phrase

com.aspose.pdf.TextFragmentAbsorber textFragmentAbsorber = new com.aspose.pdf.TextFragmentAbsorber("sample");

//accept the absorber for first page of document

pdfDocument.getPages().accept(textFragmentAbsorber);

//get the extracted text fragments into collection

com.aspose.pdf.TextFragmentCollection textFragmentCollection = textFragmentAbsorber.getTextFragments();

//loop through the Text fragments

for(com.aspose.pdf.TextFragment textFragment : (Iterable)textFragmentCollection)

{

// iterate through text segments

System.out.println(textFragment.getPage().getNumber());

for(com.aspose.pdf.TextSegment textSegment : (Iterable)textFragment.getSegments())

{

System.out.println("Text :- " + textSegment.getText());

}

}


Please feel free to contact us for any further assistance.


Best Regards,

Hi Tilal,


As I am working on textfragment class and not able to find textFragment.getPage().getNumber() in Aspsoe.pdf 11.5.0.0 version in Dot net.

Hence, is this feature PDFNEWJAVA-33510 (textFragment.getPage().getNumber()) is available in Aspose.pdf in Dot net version?

Regards,
Navnath

Hi Navnath,


Thanks for your inquiry. Please note Aspose.Pdf for Java is auto ported version of Aspose.Pdf for .NET, so subjected property is also available in Aspose.Pdf for .NET. Please check following code snippet for the purpose. Hopefully it will help you to accomplish the task.

//open document<o:p></o:p>

Document pdfDocument = new Document("Input.pdf");

//create TextAbsorber object to find all instances of the input search phrase

TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber("Aspose");

//accept the absorber for all the pages

pdfDocument.Pages.Accept(textFragmentAbsorber);

//get the extracted text fragments

TextFragmentCollection textFragmentCollection = textFragmentAbsorber.TextFragments;

//loop through the fragments

foreach (TextFragment textFragment in textFragmentCollection)

{

Console.WriteLine("Text : {0} ", textFragment.Page.Number);

}


Please feel free to contact us for any further assistance.

Best Regards,