1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
| try {
//Marges à appliquer
int margeGauche = 7;
int margeDroite = 7;
int margeHaut = 7;
int margeBas = 7;
// Type de fichier en entrée
DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
//Liste des imprimantes disponibles
PrintService[] services = PrintServiceLookup.lookupPrintServices(flavor,null);
// Propriétés de l'impression
PrintRequestAttributeSet printAttributes = new HashPrintRequestAttributeSet();
printAttributes.add(OrientationRequested.PORTRAIT);
printAttributes.add(Chromaticity.MONOCHROME);
printAttributes.add(PresentationDirection.TOBOTTOM_TOLEFT);
printAttributes.add(new MediaPrintableArea(margeGauche, margeHaut, 210
- margeDroite - margeGauche, 297 - margeBas - margeHaut, MediaPrintableArea.MM));
//Interface de communication
PrintService service = ServiceUI.printDialog(null, 100, 100, services, null, null, printAttributes);
// Annulation par l'utilisateur
if (service == null)
return (mapping.findForward("teilnehmer"));
// Ouvrir le fichier
InputStream is = new BufferedInputStream(new FileInputStream(cheminComplet));
// job d'impression
DocPrintJob job = service.createPrintJob();
SimpleDoc doc = new SimpleDoc(is, flavor, null);
//Lancement de l'impression
job.print(doc, printAttributes);
is.close();
}
catch (PrintException e) {
log.error(e.toString());
}
catch (IOException e) {
log.error(e.toString());
} |
Partager