java - How to print in pdf after deployed application -


i'm beginner in programming, i'm using eclipse kepler including windowbuilder have problem, in application, before deployed print data database (mysql) in pdf it's running after deployed(using lauch4j , innosetup compiler) 's not possible, when click on print button no reaction! can me please? function code i'm using write in pdf

public void imprimerfacture() throws documentexception {

    document document = new document(pagesize.a4);     date str = new date();     simpledateformat sdt = new simpledateformat("dd/mm/yyyy");     string strdat = sdt.format(str);     table tableau = new table(8,2);      try {       pdfwriter.getinstance(document, new fileoutputstream("src/images/facture.pdf"));      document.open()      paragraph phrase = new paragraph(new chunk("le "+strdat,fontfactory.getfont(fontfactory.courier, 10, font.bold, color.blue)).setbackground(color.yellow));     phrase.setalignment(element.align_top);     phrase.setalignment(element.align_right);     document.add(phrase);      paragraph ftitre = new paragraph("magasin   :...........",fontfactory.getfont(fontfactory.courier, 10, font.bold, color.blue));     //ftitre.setunderline(2f, -5f);     ftitre.setalignment(element.align_top);     ftitre.setalignment(element.align_left);     document.add(ftitre);      paragraph ftitre1 = new paragraph("adresse   :...........",fontfactory.getfont(fontfactory.courier, 10, font.bold, color.blue));     //ftitre.setunderline(2f, -5f);     ftitre1.setalignment(element.align_top);     ftitre1.setalignment(element.align_left);     document.add(ftitre1);       paragraph ftitre2 = new paragraph("téléphone :...........",fontfactory.getfont(fontfactory.courier, 10, font.bold, color.blue));     //ftitre.setunderline(2f, -5f);     ftitre2.setalignment(element.align_top);     ftitre2.setalignment(element.align_left);     document.add(ftitre2);      chunk chunk = new chunk("commandes disponibles",fontfactory.getfont(fontfactory.courier, 12, font.bold, color.blue));             chunk.setunderline(0.2f,-2f);              //chunk.align_center             document.add(chunk);          tableau.setautofillemptycells(true);        } catch (documentexception de) {de.printstacktrace();}        catch (ioexception ioe) {ioe.printstacktrace();}     try {         statement state = connection_bd.getinstance().createstatement(resultset.type_scroll_insensitive, resultset.concur_read_only);         resultset res = state.executequery("select referencecommande,designation,quantite,datelivraison,categorie,montantcommande,date,identifiantclient commande");         //resultsetmetadata meta = res.getmetadata();         tableau.addcell("referencecommande");         tableau.addcell("designation");         tableau.addcell("quantite");         tableau.addcell("datelivraison");         tableau.addcell("categorie");         tableau.addcell("montantcommande");         tableau.addcell("date");         tableau.addcell("identifiantclient");         tableau.setwidth(110);          while(res.next()){               tableau.addcell(res.getstring("referencecommande"));             tableau.addcell(res.getstring("designation"));             tableau.addcell(res.getstring("quantite"));             tableau.addcell(res.getstring("datelivraison"));             tableau.addcell(res.getstring("categorie"));             tableau.addcell(res.getstring("montantcommande"));             tableau.addcell(res.getstring("date"));             tableau.addcell(res.getstring("identifiantclient"));            }           document.add(tableau);         //on ferme le tout                                  res.close();         state.close();         }catch(sqlexception e){}     paragraph ftitre = new paragraph("magasinier",fontfactory.getfont(fontfactory.courier,10,font.bold,color.blue));     ftitre.setalignment(element.align_right);     document.add(ftitre);      document.close(); 

}

my function called in buttton

btnimprimer_1.addactionlistener(new actionlistener() { public void actionperformed(actionevent arg0) {

             int result=joptionpane.showconfirmdialog(null,"voulez-vous réellement imprimer ce(s) commande(s) ?","ge-shop1.0 software_message",joptionpane.yes_no_option);                  if(result==joptionpane.ok_option)                  {                     string str="select * commande";                     string strin=afficherchaine(str);                     if(strin.equals(""))                     { joptionpane.showmessagedialog(null,"cette action ne peut pas aboutir du fait qu'il n'y rien à imprimer!!!\n veuillez saisir la(les) nouvelle(es) commande(es) et puis proceder l'impression !","ge-shop1.0 software_message",joptionpane.warning_message);}                     else {try {                  //if (listachat.size() > 0){                       imprimerfacture();                           if(desktop.isdesktopsupported()){                             if(desktop.getdesktop().issupported(java.awt.desktop.action.open)){                             try {                                 java.awt.desktop.getdesktop().open(new file("src/images/facture.pdf"));                             } catch (ioexception ex) {                                 //traitement de l'exception                             }                             catch (illegalargumentexception e){}                             } else {                                 joptionpane.showmessagedialog(null, "la fonction n'est pas supportée par votre système d'exploitation","ge-shop1.0 software_message", joptionpane.error_message);                             }                         }else{                             joptionpane.showmessagedialog(null, "desktop pas supportée par votre système d'exploitation", "ge-shop1.0 software_message", joptionpane.error_message);                         }                   } catch (documentexception e) {                 // todo auto-generated catch block                 e.printstacktrace();                   }                  }}                   else{if(result==joptionpane.no_option)                 {joptionpane.showmessagedialog(null, "l'operation d'impression vient d'etre annulée", "ge-shop1.0 software_message", joptionpane.information_message);}                  }                }     }); 

the path problem.

pdfwriter.getinstance(document, new fileoutputstream("src/images/facture.pdf")); 

better reserve own directory read/write data, typically in user's home. create temporary file (see file).

file applicationdir = new file(system.getproperty("user.home")     + file.sepator + ".ge-shop"); applicationdir.mkdirs(); file pdffile = new file(applicationdir, "facture.pdf"); pdfwriter.getinstance(document, new fileoutputstream(pdffile)); 

...

desktop.getdesktop().open(pdffile); 

Comments