haf Posted November 16, 2009 Share Posted November 16, 2009 Hi,is it possible to generate signed (and certified) PDF-files using JasperReports?Thanks for any adviceRegardsHaf Link to comment Share on other sites More sharing options...
pablodc Posted November 24, 2009 Share Posted November 24, 2009 Hi Haf, You can't sign PDF using JasperReports. You must export the report to PDF format and then use iText to sign them. You have examples at this URL to do that: http://itextpdf.sourceforge.net/howtosign.html Good luck! Link to comment Share on other sites More sharing options...
z3gator Posted November 24, 2009 Share Posted November 24, 2009 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 More sharing options...
haf Posted November 25, 2009 Author Share Posted November 25, 2009 Hi pablodc, thanks for your response.I know iText very well, however I thought JasperReport provides any solution.So I will use iText. Thanks Link to comment Share on other sites More sharing options...
haf Posted November 25, 2009 Author Share Posted November 25, 2009 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 More sharing options...
teodord Posted November 25, 2009 Share Posted November 25, 2009 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 More sharing options...
z3gator Posted March 8, 2010 Share Posted March 8, 2010 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now