Jump to content
We've recently updated our Privacy Statement, available here ×

How to generate a signed PDF using JasperReports


haf

Recommended Posts

  • Replies 6
  • Created
  • Last Reply

Top Posters In This Topic

I have used itext to add a digital signature to a PDF, but in moving to iReport I cannot tell whether there is a way for me to find out where (i.e. page, x, y coordinates) the signature field was positioned in order to position the visible signature.  One alternative (which might be useful in general) might be to create an acrofield for the signature, which could later be found in the PDF, but I don't see any indication that it's possible to create form fields via iReport/Jasper.

Thanks for any suggestions.

 

Link to comment
Share on other sites

Hi z3gator,

 

it is not necessary to use a "visible" signature to sign a PDF.

Otherwise, you have the possibility to create with iText an AcroField in the resulting PDF from JasperReport and set in this field the visible Signature.

 

But, I do not know a solution to create such fields with JasperReport.

 

Regards

 

Haf

Link to comment
Share on other sites

Hi,

 

You can implement such exporter customization in JasperReports using a generic element in the report template and then implement a generic element handler for the JRPdfExporter.

So JR/iR lets you do such thing, is just that you need to write some code to leverage the specific iText library feature that you want.

 

You can check the /demo/samples/genericelement sample provided with JR, to see what generic elements could be.

 

I hope this helps.
Teodor

 

Link to comment
Share on other sites

  • 3 months later...

 While not necessary to create a visible signature, that's what our requirements were.  While I looked at the generic element support, I ended up using what I believed to be a simpler solution: I placed an anchor in the PDF where I wanted to place the signature and then used a PdfStamper to add the digital signature. 

The iReport snippet is just:

  <anchorNameExpression><![CDATA[new String("SIGNED_BY")]]></anchorNameExpression>

and then the logic to extract the location from the anchor is:
 
            String[] dest = getNamedDestination(reader, "SIGNED_BY");
            if (dest != null) {
                try {
                    sigData.setSigPageNumber(Integer.parseInt(dest[0]));
                    sigData.setSigLowerLeftX(Float.parseFloat(dest[1]));
                    sigData.setSigLowerLeftY(Float.parseFloat(dest[2])+3.0f);
                    sigData.setSigUpperRightX(sigData.getSigLowerLeftX()+150.0f);
                    sigData.setSigUpperRightY(sigData.getSigLowerLeftY()+32.0f);
                    if (logger.isDebugEnabled())
                        logger.debug("Set signature location to page "+sigData.getSigPageNumber()+" at "+
                                sigData.getSigLowerLeftX()+","+sigData.getSigLowerLeftY()+", "+
                                sigData.getSigUpperRightX()+", "+sigData.getSigUpperRightY());
                } catch (Exception e) {
                    logger.error("Caught exception processing destination: "+Arrays.asList(dest), e);
                }
            }
        }
    
    public static String[] getNamedDestination(PdfReader reader, String name) throws Exception {
        String[] parts = StringUtils.split((String)SimpleNamedDestination.getNamedDestination(reader, false).get(name), " ");
        return (parts == null || parts.length < 4) ? null :
            new String[] {parts[0], parts[2], parts[3]};
    }
 
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...