cs_redbar
Messages postés112Date d'inscriptionmardi 26 janvier 2010StatutMembreDernière intervention26 mai 2014
-
24 oct. 2011 à 19:25
cs_redbar
Messages postés112Date d'inscriptionmardi 26 janvier 2010StatutMembreDernière intervention26 mai 2014
-
26 oct. 2011 à 15:46
Bonjour à tous
Je bute un peu sur un travail. J'ai créer un fichier PDF avec l'API itext pour l'imprimer. Mais mon souci est que le fichier une fois créé n'apparait pas automatiquement pour que je puisse lancer l'impression. Pour faire donc l'impression il me faut aller dans le reppertoire du fichier pour l'ouvrir avant de l'imprimer. Je voudrais que le fichier dès qu'il est créé s'ouvre automatiquement pour que je puisse l'imprimer.
Voici mon code de création de mon fichier
class ImprimerlivreListener implements ActionListener{
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
Document document = new Document(PageSize.A4);
try{
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("rapport/Livredecredit.pdf"));
document.addTitle("Livre de credit");
document.addAuthor("Athanase KOUASSI");
document.addSubject("Génération de PDF.");
document.addKeywords("iText, gestion de stock");
document.open();
//Recupere la date système
Date date = new Date();
//formater la date
SimpleDateFormat sdf = new SimpleDateFormat("dd MMMM yyyy");
Paragraph paragraphe = new Paragraph("Date : "+sdf.format(date));
paragraphe.setAlignment(Paragraph.ALIGN_RIGHT);
document.add(new Paragraph(" "));
//document.add(new Paragraph(" "));
document.add(paragraphe);
document.add(new Paragraph(" "));
document.add(new Paragraph(" "));
document.add(new Paragraph("Client : "+ nom.toUpperCase()));
document.add(new Paragraph("Contact : "+contact));
document.add(new Paragraph(" "));
document.add(new Paragraph(" "));
document.add(new Paragraph(" "));
Paragraph paratitre = new Paragraph("LIVRE DE CREDIT", FontFactory.getFont(FontFactory.COURIER, 20f,Font.BOLD));
paratitre.setAlignment(Paragraph.ALIGN_CENTER);
document.add(paratitre);
Statement state = Maconnexion.getInstance().createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
ResultSet res state.executeQuery("SELECT TO_CHAR(datfact, 'DD/MM/YYYY'),TO_CHAR(id_fact,'9999'),TO_CHAR(restapayer,'9999999') FROM facture WHERE facture.id_client'"+idClient+"' AND restapayer > 0 ORDER BY datfact");
//pour obtenir le nombre de lignes du tableau à imprimer
ResultSetMetaData resmeta = res.getMetaData();
res.last();
//nombre de ligne du tableau à imprimer
int nbLigne = res.getRow()+1;
//tableau(nbrecolonnes,nbrelignes)
Table tableau = new Table(3,nbLigne);
tableau.setAutoFillEmptyCells(true);
tableau.setPadding(2);
Cell cell = new Cell("Date Facture");
cell.setHeader(true);
cell.setBackgroundColor(Color.darkGray.brighter().brighter().brighter());
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
tableau.addCell(cell);
cell = new Cell("Numero facture");
cell.setHeader(true);
cell.setBackgroundColor(Color.darkGray.brighter().brighter().brighter());
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
tableau.addCell(cell);
cell = new Cell("Montant à payer");
cell.setHeader(true);
cell.setBackgroundColor(Color.darkGray.brighter().brighter().brighter());
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
tableau.addCell(cell);
tableau.endHeaders();
res.beforeFirst();
while(res.next()){
for(int i = 1; i <= resmeta.getColumnCount(); i++){
Chunk chunk = new Chunk( (String) res.getObject(i));
Phrase phrase = new Phrase(chunk);
tableau.addCell(phrase);
}
}
document.add(tableau);
document.add(new Paragraph(" Total des sommes dues à ce jour "+new Conversion().convertirEntierString(soldeDuClient(idClient)), FontFactory.getFont(FontFactory.COURIER, 15f,Font.BOLD)));
res.close();
state.close();
}catch(SQLException as){
as.printStackTrace();
}catch (DocumentException de) {
de.printStackTrace();
} catch (IOException ioe) {
ioe.printStackTrace();
}
document.close();
}
}