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

Documents Java Discussion :

[iText] Ecrire sur un fichier pdf en jar


Sujet :

Documents Java

  1. #1
    Candidat au Club
    Homme Profil pro
    Développeur Java
    Inscrit en
    Février 2017
    Messages
    3
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Cameroun

    Informations professionnelles :
    Activité : Développeur Java
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Février 2017
    Messages : 3
    Points : 3
    Points
    3
    Par défaut [iText] Ecrire sur un fichier pdf en jar
    Svp j'ai besoin d'une aide en java... j'ai conçu une application mais actuellement je butté sur un problème: je sort les factures sous un fichier pdf, mais lors du déploiement en fichier jar, mais les fonctions itextpdf que j'utilise ne fonction pas quand je lance le fichier jar c'est à dire les données qui devrai etre écritent dans le fichier pdf ne s'écrive pas, mais crée quand même un fichier pdf, mais vide...

  2. #2
    Candidat au Club
    Homme Profil pro
    Développeur Java
    Inscrit en
    Février 2017
    Messages
    3
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Cameroun

    Informations professionnelles :
    Activité : Développeur Java
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Février 2017
    Messages : 3
    Points : 3
    Points
    3
    Par défaut Code1 pdf
    Voila mon code quand j'enlève les parties en bleu du code, qui concerne la mise des images en filigrane sur le doc pdf, les données sont écrites sur le doc pdf... svp aidez moi à resoudre ce problème... merci

    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
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    public void toPdf(){
            conn = new connect_bdd().conn;
            String sql= "SELECT * FROM outillage";
            Document doc = new Document(PageSize.A4, 36, 36, 50, 100);
            try{    
                    Date dat =new Date();
                    DateFormat fd=DateFormat.getDateInstance(DateFormat.LONG);
                        
                    FileSystemView fl=FileSystemView.getFileSystemView();
                    File fie=fl.getDefaultDirectory();
                    File dirpdf =new File(fie+"\\Facture\\InvOutil"+fd.format(dat));
                    dirpdf.mkdirs();
                    int list=dirpdf.listFiles().length;
                    fc=list;                 
                    File pdf = new File(dirpdf + "\\Outil("+fc+").pdf");
                    PdfWriter writer = PdfWriter.getInstance(doc , new FileOutputStream(pdf));
                    
                    Image img = Image.getInstance("src\\Imagemaint\\entete w.png");
                    img.scaleAbsoluteHeight(100);
                    img.scaleAbsoluteWidth(580);
                    writer.setPageEvent(new MonPageEvent(img, 0, 0));
                    
                    Image img1 = Image.getInstance("src\\Imagemaint\\pied w.png");
                    img1.scaleAbsoluteHeight(70);
                    img1.scaleAbsoluteWidth(575);
                    writer.setPageEvent(new MonPageEvent1(img1, 0, 0));
                    
                    Image img2 = Image.getInstance("src\\Imagemaint\\pied direc.png");
                    img2.scaleAbsoluteHeight(20);
                    img2.scaleAbsoluteWidth(425);
                    writer.setPageEvent(new MonPageEvent2(img2, 50, 150));
                    
                    doc.open();
                    
                    Date gmt=new Date();
                    DateFormat gs=DateFormat.getDateInstance(DateFormat.SHORT);
                    String jours=gs.format(gmt).split("/")[0];
                    String moiss=gs.format(gmt).split("/")[1];
                    String ans=gs.format(gmt).split("/")[2];
                    String dits="20"+ans+"-"+moiss+"-"+jours;
                    String dits1 = jours + "/" +moiss+ "/" + "20"+ans;
            
                    doc.add(new Paragraph(" \n\n"));
                    doc.add(new Paragraph(" "));
                    doc.add(new Paragraph(" "));
                    Paragraph para0 = new Paragraph();
                    para0.add(new Chunk(" Garoua le : " + dits1 , new Font(Font.FontFamily.TIMES_ROMAN, 12)));
                    para0.setAlignment(Element.ALIGN_RIGHT);
                    doc.add(para0);
                    
                    doc.setMargins(35f, 35f, 150f, 200f);
                    doc.add(new Paragraph(" \n\n"));
                    
                    Paragraph para = new Paragraph();
                    para.add(new Chunk(" Récapitulatif Des Outils EWS /" +ans , new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD)).setUnderline(0.2f, -2f));
                    para.setAlignment(Element.ALIGN_CENTER);
                    doc.add(para);
                    doc.add(new Paragraph(" "));
                    
                    PdfPTable table = new PdfPTable(3);
                    table.setWidthPercentage(100);
                    PdfPCell cell;
                    ////  Debut Entete du tableau
                    cell = new PdfPCell(new Phrase("Code_Outil", new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD)));
                    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                    cell.setBackgroundColor(BaseColor.CYAN);
                    table.addCell(cell);
                    
                    cell = new PdfPCell(new Phrase("Désignation", new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD)));
                    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                    cell.setBackgroundColor(BaseColor.CYAN);
                    table.addCell(cell);
                    
                    cell = new PdfPCell(new Phrase("Quantité", new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD)));
                    cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                    cell.setBackgroundColor(BaseColor.CYAN);
                    table.addCell(cell);              
                    ///// Fin entete du Tableau
                        try
                            {
                                 ResultSet str=conn.createStatement().executeQuery(sql);
                                while(str.next())
                                    {
                                        System.out.println("PDF CORRECT");
                                        String cod = str.getString("code_outil");
                                        String desi = str.getString("designation_outil");
                                        String quan = str.getString("quantite");
                                        cell = new PdfPCell(new Phrase(cod, new Font(Font.FontFamily.TIMES_ROMAN, 11)));
                                        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                                        table.addCell(cell);
                                        cell = new PdfPCell(new Phrase(desi, new Font(Font.FontFamily.TIMES_ROMAN, 11)));
                                        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                                        table.addCell(cell);
                                        cell = new PdfPCell(new Phrase(quan, new Font(Font.FontFamily.TIMES_ROMAN, 11)));
                                        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
                                        
                                        table.addCell(cell);               
                                        
                                        }
                                    }catch(Exception g){
                                        g.printStackTrace();
                                    }
                        doc.add(table);
                        float a = doc.getPageSize().getHeight() - doc.topMargin() - doc.bottomMargin();
                        System.out.println(a);
                        System.out.println(doc.topMargin());
                        System.out.println(doc.bottomMargin());
                        
                    doc.close();
                    
                    Desktop.getDesktop().open(new File(dirpdf+"\\Outil("+fc+").pdf"));
                }
            catch(Exception e)
                { 
                    e.printStackTrace(); 
                }
        }

Discussions similaires

  1. [FPDI] ecrire sur un fichier PDF
    Par erman_yazid dans le forum Bibliothèques et frameworks
    Réponses: 5
    Dernier message: 17/03/2009, 09h36
  2. lire et ecrire sur un fichier Text
    Par touf213 dans le forum C++Builder
    Réponses: 2
    Dernier message: 03/07/2007, 22h33
  3. Info sur un fichier pdf
    Par pedro226 dans le forum Delphi
    Réponses: 2
    Dernier message: 03/04/2007, 18h35
  4. lien sur un fichier pdf
    Par canabral dans le forum Balisage (X)HTML et validation W3C
    Réponses: 8
    Dernier message: 06/02/2006, 11h26
  5. [C#] Authentification sur les fichiers Pdf
    Par ensisoft dans le forum ASP.NET
    Réponses: 14
    Dernier message: 04/05/2004, 12h10

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