About Me

My photo
Ernakulam, Kerala, India
I am Sajadh, author of this blog. I run this with loads of passion.
If you are into java, you may find lot of interesting things around ...
Advance thanks for your queries to sajadhaja90@gmail.com.

Friday, 5 April 2013

My Stuff Doc - jasper-export-1.0.jar


1 .Export To PDF

Tools needed :-  jasper-export-1.0.jar  (owner : Mohammed Sajadh N.A)
4 Steps :-
         1. Take Connection from database
           eg:-  Connection con = new com.sajadhaja.connection.DatabaseConnection().getConnection();
         2.  Set all dynamic parameters that in jrxml file to Hash Map like
           eg:-  Map<String, Object> hm = new HashMap<String, Object>();
                   hm.put("p1_in_jrxml", 1);
                   hm.put("p2_in_jrxml ", "12 Aug 2013");
        3. Import class JasperExport  from my jar (jasper-export-1.0.jar)   and set  all parameters like
                  eg:- JasperExport jp = new JasperExport("jrxml/jasper file location",
                                                                  "out PDF file location",connection, hashmap);
       4. Call function exportToPDF()

Sample Example :-
Public class ExportToPDF{
public static void main(String args[]) {
        Connection con = new com.sajadhaja.connection.DatabaseConnection().getConnection();
        Map<String, Object> hm = new HashMap<String, Object>();
        hm.put("p1", 1);
        hm.put("p2", "");
        JasperExport jp = new JasperExport("D:\\sample.jasper", "D:\\sample.pdf", con, hm);
        jp.exportToPDF();
    }
}

OTHER FUNCTIONS

To customize PDF for having following functions:-
1.      Default Magnification
2.      Encrypt PDF
3.      Setting MetaData
4.      Compress PDF
Replace function used in STEP 4 with   exportToCustomPDF(JasperPDFParam pm);
Where class JasperPDFParam contain all funtions to do the same.
1.      Default Magnification
To open the PDF doc in default zoom level, you can set it here
Syntax:-  void setDefaultZoom(int Zoompercentage)
Eg:-
JasperPDFParam pm = new JasperPDFParam();
pm.setDefaultZoom(100);  
2.      Encrypt PDF
Syntax:- void setEncryption(boolean is128bitkey, String userPassword, String ownerPassword, int permissions)
Where field ‘permissions’ have following values
                 JasperPDFParam.PERMISSION_AllowPrinting
                 JasperPDFParam.PERMISSION_AllowModifyContents
                 JasperPDFParam.PERMISSION_AllowCopy
                 JasperPDFParam.PERMISSION_AllowModifyAnnotations
                 JasperPDFParam.PERMISSION_AllowFillIn
                 JasperPDFParam.PERMISSION_AllowScreenReaders
                 JasperPDFParam.PERMISSION_AllowAssembly
                 JasperPDFParam PERMISSION_AllowDegradedPrinting
Eg:-
JasperPDFParam pm = new JasperPDFParam();
pm.setEncryption(true, "12345", "0000",
new Integer(JasperPDFParam.PERMISSION_AllowAssembly|JasperPDFParam.PERMISSION_AllowCopy));
       
3.      Setting MetaData
Syntax:- void setMetadata(String tittle, String author, String subject, String keywords, String creator);
Eg:-
JasperPDFParam pm = new JasperPDFParam();
pm.setMetadata("Jasper Notes", "Mohammed", "Export pdf notes", "jasper jar", "sajadhaja.blogspot.in");

4.      Compress PDF
Syntax :- void pm.setCompressed(boolean isCompressed);
Eg:-
JasperPDFParam pm = new JasperPDFParam();
pm.setCompressed(true);


Sample Example :-
Public class ExportToPDF{
public static void main(String args[]) {
Connection con = new com.sajadhaja.connection.DatabaseConnection().getConnection();
            Map<String, Object> hm = new HashMap<String, Object>();
            hm.put("p1", 1);
            hm.put("p2", "");
            JasperExport jp = new JasperExport("D:\\sample.jasper", "D:\\sample.pdf", con, hm);
            JasperPDFParam pm = new JasperPDFParam();
            pm.setMetadata("mohammed tittle", "mohamed author", "mohammed subject", "mohammed keywords", "mohamed    creator");
            pm.setEncryption(true, "12345", "0000", new Integer(JasperPDFParam.PERMISSION_AllowAssembly|JasperPDFParam.PERMISSION_AllowCopy));
            pm.setDefaultZoom(100);
            pm.setCompressed(true);
            jp.exportToCustomPDF(pm);
     }}


2 comments:

  1. Hi,

    I have searched for jasper-export-1.0.jar... there is no such jar... can u mention the link..??????

    ReplyDelete
    Replies
    1. This jar is created by me. and is not uplaoded anywhere

      Delete

You can enter queries here...