IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Java Discussion :

[Impression]imprimer différents format


Sujet :

Java

  1. #1
    Membre régulier
    Profil pro
    Inscrit en
    Août 2005
    Messages
    221
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2005
    Messages : 221
    Points : 84
    Points
    84
    Par défaut [Impression]imprimer différents format
    Bonjour,

    je voudrais savoir comment faire pour imprimer sur une longueur voulue.
    En effet j'imprime sur des bandelettes d'étiquette et la longueur fait 30,4 cms.
    Comme l'imprimante doit etre prévue pour du A4, je ne peux donc pas imprimer sur la fi de la bandelette!!!

    Merci

  2. #2
    Rédacteur/Modérateur

    Avatar de bouye
    Homme Profil pro
    Information Technologies Specialist (Scientific Computing)
    Inscrit en
    Août 2005
    Messages
    6 840
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : Nouvelle-Calédonie

    Informations professionnelles :
    Activité : Information Technologies Specialist (Scientific Computing)
    Secteur : Agroalimentaire - Agriculture

    Informations forums :
    Inscription : Août 2005
    Messages : 6 840
    Points : 22 854
    Points
    22 854
    Billets dans le blog
    51
    Par défaut
    Tu peux te definir ton propre format de Paper et creer un PageFormat a partir de cet objet. J'ignore cependant comment raccrocher ca a l'imprimante.
    Merci de penser au tag quand une réponse a été apportée à votre question. Aucune réponse ne sera donnée à des messages privés portant sur des questions d'ordre technique. Les forums sont là pour que vous y postiez publiquement vos problèmes.

    suivez mon blog sur Développez.

    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning. ~ Rich Cook

  3. #3
    Membre régulier
    Profil pro
    Inscrit en
    Août 2005
    Messages
    221
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2005
    Messages : 221
    Points : 84
    Points
    84
    Par défaut
    A force de lecture depuis mon message j'avais trouver la meme solution que celle que tu me proposes. Cela conforte mon idée que du coup c'est peut etre possible!!

    Pour l'imprimante je pense que ca peut passer car j'imprime sur une imprimante matricielle. A essayer!!

    Merci pour ta reponse!!

  4. #4
    Membre régulier
    Profil pro
    Inscrit en
    Août 2005
    Messages
    221
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2005
    Messages : 221
    Points : 84
    Points
    84
    Par défaut
    Et oui maintenant il y a le probleme de l'imprimante.....

    Si quelqu'un sait comment dire à une imprimante la taille de la page que l'on veut imprimer....

    Merci d'avance!!

  5. #5
    BiM
    BiM est déconnecté
    Expert éminent sénior
    Avatar de BiM
    Femme Profil pro
    Consultante/Formatrice BIRT & Ingénieur Java/J2EE/GWT
    Inscrit en
    Janvier 2005
    Messages
    7 796
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 38
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Consultante/Formatrice BIRT & Ingénieur Java/J2EE/GWT

    Informations forums :
    Inscription : Janvier 2005
    Messages : 7 796
    Points : 10 765
    Points
    10 765
    Par défaut
    Class Printable, méthode print() :

    Method Detail

    print
    public int print(Graphics graphics,
    PageFormat pageFormat,
    int pageIndex)
    throws PrinterExceptionPrints the page at the specified index into the specified Graphics context in the specified format. A PrinterJob calls the Printable interface to request that a page be rendered into the context specified by graphics. The format of the page to be drawn is specified by pageFormat. The zero based index of the requested page is specified by pageIndex. If the requested page does not exist then this method returns NO_SUCH_PAGE; otherwise PAGE_EXISTS is returned. The Graphics class or subclass implements the PrinterGraphics interface to provide additional information. If the Printable object aborts the print job then it throws a PrinterException.

    Parameters:
    graphics - the context into which the page is drawn
    pageFormat - the size and orientation of the page being drawn
    pageIndex - the zero based index of the page to be drawn
    Returns:
    PAGE_EXISTS if the page is rendered successfully or NO_SUCH_PAGE if pageIndex specifies a non-existent page.
    Throws:
    PrinterException - thrown when the print job is terminated.

  6. #6
    Membre régulier
    Profil pro
    Inscrit en
    Août 2005
    Messages
    221
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2005
    Messages : 221
    Points : 84
    Points
    84
    Par défaut
    ok j'utilise deja

    mais lorsque j'imprime en définissant la dimension du pageFormat l'imprimante n'imprime pas la partie au dela d'une page A 4!!!

  7. #7
    Membre régulier
    Profil pro
    Inscrit en
    Août 2005
    Messages
    221
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2005
    Messages : 221
    Points : 84
    Points
    84
    Par défaut
    Si tu peux etre plus précis avec un bout de code peut etre STP


    Merci!

  8. #8
    BiM
    BiM est déconnecté
    Expert éminent sénior
    Avatar de BiM
    Femme Profil pro
    Consultante/Formatrice BIRT & Ingénieur Java/J2EE/GWT
    Inscrit en
    Janvier 2005
    Messages
    7 796
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 38
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Consultante/Formatrice BIRT & Ingénieur Java/J2EE/GWT

    Informations forums :
    Inscription : Janvier 2005
    Messages : 7 796
    Points : 10 765
    Points
    10 765
    Par défaut
    Ah Peut être que tu dois préciser le bac ou je sais pas quoi dans le PageFormat.

    Y'a un truc dans PageAttributes :

    getMedia
    public PageAttributes.MediaType getMedia()Returns the paper size for pages using these attributes. This attribute is updated to the value chosen by the user.

    Returns:
    one of the constant fields of the MediaType class.

  9. #9
    Membre régulier
    Profil pro
    Inscrit en
    Août 2005
    Messages
    221
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2005
    Messages : 221
    Points : 84
    Points
    84
    Par défaut
    c une imprimante matricielle pour imprimer des etiquettes...

    t'as deja réussi à imprimer sur unformat nien spécifique?

  10. #10
    BiM
    BiM est déconnecté
    Expert éminent sénior
    Avatar de BiM
    Femme Profil pro
    Consultante/Formatrice BIRT & Ingénieur Java/J2EE/GWT
    Inscrit en
    Janvier 2005
    Messages
    7 796
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 38
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Consultante/Formatrice BIRT & Ingénieur Java/J2EE/GWT

    Informations forums :
    Inscription : Janvier 2005
    Messages : 7 796
    Points : 10 765
    Points
    10 765
    Par défaut
    J'ai jamais imprimer avec Java, j'essaye simplement de t'aider, il est interessant ton problème et il est très possible que je m'y penche d'ici quelques mois

    EDIT : Ca m'aiderait si tu mettais le code que tu as fais jusque là (nécessaire à l'impression)

  11. #11
    Membre régulier
    Profil pro
    Inscrit en
    Août 2005
    Messages
    221
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2005
    Messages : 221
    Points : 84
    Points
    84
    Par défaut
    C clair

    t'es le seul ki me repond et ca fait deja plusieurs fois ke je pose des questions sur le forum...

    J'arrive a me dépatouiller mais comme j'imprime des bandes d'étiquettes en grands nombres c'est chiant car à chaque fois j'écris pas sur la dernière...

  12. #12
    BiM
    BiM est déconnecté
    Expert éminent sénior
    Avatar de BiM
    Femme Profil pro
    Consultante/Formatrice BIRT & Ingénieur Java/J2EE/GWT
    Inscrit en
    Janvier 2005
    Messages
    7 796
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 38
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Consultante/Formatrice BIRT & Ingénieur Java/J2EE/GWT

    Informations forums :
    Inscription : Janvier 2005
    Messages : 7 796
    Points : 10 765
    Points
    10 765
    Par défaut
    LA seule...

    Sinon lis mon EDIT please

  13. #13
    Membre régulier
    Profil pro
    Inscrit en
    Août 2005
    Messages
    221
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2005
    Messages : 221
    Points : 84
    Points
    84
    Par défaut
    Scuse...

  14. #14
    Membre régulier
    Profil pro
    Inscrit en
    Août 2005
    Messages
    221
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2005
    Messages : 221
    Points : 84
    Points
    84
    Par défaut
    J'ai donc 2 classes:
    1 pour lancer une fenetre et un bouton pour imprimer
    L'autre qui implemante l'interface Printable

    Voila le code:

    public class Fenetre extends JFrame implements ActionListener{

    JButton button;
    JobImpression job;
    HashPrintRequestAttributeSet attributes;

    public Fenetre(){
    setTitle("Test impression 8 ième étiquette");
    setSize(500,500);

    job = new JobImpression();
    button = new JButton("Imprimer");
    button.addActionListener(this);
    getContentPane().add(button);
    attributes = new HashPrintRequestAttributeSet();

    setVisible(true);
    }

    public void actionPerformed(ActionEvent e){
    if(e.getSource() == button){
    try{
    PrinterJob printerJob = PrinterJob.getPrinterJob();
    printerJob.setPrintable(job);
    if(printerJob.printDialog(attributes))
    printerJob.print(attributes);
    }
    catch(Exception a){
    System.out.println("probleme de parametrage");
    }
    }
    }
    public static void main(String[] args) {
    Fenetre f = new Fenetre();
    }
    }



    public class JobImpression implements Printable{

    public int print(Graphics g,PageFormat pf, int page){
    if(page >= 1)
    return Printable.NO_SUCH_PAGE;
    Paper papier = new Paper();
    papier.setSize(500,900);
    pf.setPaper(papier);
    g.drawString("Hello de sebus",200,830);
    g.drawString("Hello de fabien",200,200);

    return Printable.PAGE_EXISTS;
    }
    }


  15. #15
    BiM
    BiM est déconnecté
    Expert éminent sénior
    Avatar de BiM
    Femme Profil pro
    Consultante/Formatrice BIRT & Ingénieur Java/J2EE/GWT
    Inscrit en
    Janvier 2005
    Messages
    7 796
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 38
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Consultante/Formatrice BIRT & Ingénieur Java/J2EE/GWT

    Informations forums :
    Inscription : Janvier 2005
    Messages : 7 796
    Points : 10 765
    Points
    10 765
    Par défaut
    Arg, j'arrive pas à tout comprendre, ça m'a l'air complexe. J'veux bien bûcher dessus si tu mets les balises code please avec l'indentation, on y verra plus clair. Merci !

  16. #16
    Membre régulier
    Profil pro
    Inscrit en
    Août 2005
    Messages
    221
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2005
    Messages : 221
    Points : 84
    Points
    84
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
     
    public class Fenetre extends JFrame implements ActionListener{
     
    	JButton button;
    	JobImpression job;
    	HashPrintRequestAttributeSet attributes;
     
    	public Fenetre(){
    		setTitle("Test impression 8 ième étiquette");
    		setSize(500,500);
     
    		job = new JobImpression();
    		button = new JButton("Imprimer");
    		button.addActionListener(this);
    		getContentPane().add(button);
    		attributes = new HashPrintRequestAttributeSet();
     
    		setVisible(true);
    	}
     
    	public void actionPerformed(ActionEvent e){
    		if(e.getSource() == button){
    			try{
    			PrinterJob printerJob = PrinterJob.getPrinterJob();
    			printerJob.setPrintable(job);
    			if(printerJob.printDialog(attributes))
    				printerJob.print(attributes);
    			}
    			catch(Exception a){
    				System.out.println("probleme de parametrage");
    			}
    		}
    	}
    	public static void main(String[] args) {
    		Fenetre f = new Fenetre();
    	}
    }
     
     
     
     
     
     
     
     
     
     
    public class JobImpression implements Printable{
     
    	public int print(Graphics g,PageFormat pf, int page){
    		if(page >= 1)
    			return Printable.NO_SUCH_PAGE;
    		Paper papier = new Paper();
    		papier.setSize(500,900);
    		pf.setPaper(papier);
    		g.drawString("Hello de sebus",200,830);
    		g.drawString("Hello de fabien",200,200);
     
    		return Printable.PAGE_EXISTS;
    	}
    }

    Je te rassure c'est complexe (a mon avis)
    C'est pour ca que y'a pas grand monde pour répondre!!!

  17. #17
    BiM
    BiM est déconnecté
    Expert éminent sénior
    Avatar de BiM
    Femme Profil pro
    Consultante/Formatrice BIRT & Ingénieur Java/J2EE/GWT
    Inscrit en
    Janvier 2005
    Messages
    7 796
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 38
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Consultante/Formatrice BIRT & Ingénieur Java/J2EE/GWT

    Informations forums :
    Inscription : Janvier 2005
    Messages : 7 796
    Points : 10 765
    Points
    10 765
    Par défaut
    Dans le print du JobImpression, après le papier.setSize(...), fait un :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    System.out.println("Hauteur : "+papier.getImageableHeight());
    System.out.println("Largeur : "+papier.getImageableWidth());
    Qu'obtiens tu à l'affichage ?

  18. #18
    Membre régulier
    Profil pro
    Inscrit en
    Août 2005
    Messages
    221
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2005
    Messages : 221
    Points : 84
    Points
    84
    Par défaut
    J'obtiens:

    Hauteur: 648.0
    Largeur: 468.0
    Hauteur: 648.0
    Largeur: 468.0


    sachant qu'une page A4 fait
    hauteur: 842
    largeur: 595

  19. #19
    BiM
    BiM est déconnecté
    Expert éminent sénior
    Avatar de BiM
    Femme Profil pro
    Consultante/Formatrice BIRT & Ingénieur Java/J2EE/GWT
    Inscrit en
    Janvier 2005
    Messages
    7 796
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Âge : 38
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Consultante/Formatrice BIRT & Ingénieur Java/J2EE/GWT

    Informations forums :
    Inscription : Janvier 2005
    Messages : 7 796
    Points : 10 765
    Points
    10 765
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    papier.setImageableArea(double posX,double posY,double largeur,double hauteur);
    setImageableArea
    public void setImageableArea(double x,
    double y,
    double width,
    double height)Sets the imageable area of this Paper. The imageable area is the area on the page in which printing occurs.

    Parameters:
    width - the value to which to set the width of the imageable area of this Paper
    height - the value to which to set the height of the imageable area of this Paper

  20. #20
    Membre régulier
    Profil pro
    Inscrit en
    Août 2005
    Messages
    221
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2005
    Messages : 221
    Points : 84
    Points
    84
    Par défaut
    L'imprimante n'a pas air d'en prendre compte...

Discussions similaires

  1. [impression] imprimer le contenu d'une url
    Par FFF dans le forum Autres Logiciels
    Réponses: 4
    Dernier message: 30/11/2005, 15h07
  2. [Impression] Imprimer avec jbuilder
    Par joker34 dans le forum JBuilder
    Réponses: 3
    Dernier message: 15/11/2005, 13h15
  3. impression contenu db de manière formatée
    Par micknic dans le forum Balisage (X)HTML et validation W3C
    Réponses: 5
    Dernier message: 04/10/2004, 11h53
  4. [Impression] Imprimer un JTable
    Par VincenzoR dans le forum Composants
    Réponses: 4
    Dernier message: 04/05/2004, 18h41

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo