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

avec Java Discussion :

Texte rendering mode avec PDFBox


Sujet :

avec Java

  1. #1
    Membre à l'essai
    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2013
    Messages
    16
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Liban

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juin 2013
    Messages : 16
    Points : 13
    Points
    13
    Par défaut Texte rendering mode avec PDFBox
    Salut à tous,

    Je suis entrain d'effectuer un "text rendering mode" avec PDFBox. J'ai écrit ce code mais je ne sais pas comment faut il appeler la fonction "process"??.
    Voici mon code:

    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
    public class Test1 extends OperatorProcessor{
        private static final String src="...";
        private static PDFStreamEngine pp;
        private static PDPageContentStream content;
        private static PDType1Font font; 
        public static void CreatePdf(String src) throws IOException, COSVisitorException{
        PDRectangle rec= new PDRectangle(400,400);
        PDDocument document= null;
        document = new PDDocument();
        PDPage page = new PDPage(rec);
        document.addPage(page);
        PDDocumentInformation info=document.getDocumentInformation();
        info.setAuthor("PdfBox");
        info.setCreator("Pdf");
        info.setSubject("Stéganographie");
        info.setTitle("Stéganographie dans les documents PDF");
        info.setKeywords("Stéganographie, pdf");
        content= new PDPageContentStream(document, page);
        pp=new PDFStreamEngine();
        font= PDType1Font.HELVETICA;
        String texte="hello";
        content.beginText();
        content.setFont(font, 12);
        content.moveTextPositionByAmount(15, 385);           
        content.drawString(texte);
        content.endText();
        content.close();
        document.save("doc.pdf");
        document.close();       
        }
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) throws IOException, COSVisitorException {
            // TODO code application logic here   
            Test1 tes= new Test1();
            tes.CreatePdf(src);
        }
        @Override
        public void process(PDFOperator pdfo, List<COSBase> list) throws IOException {
                 COSNumber mode = (COSNumber)list.get(0);
                pp.getGraphicsState().getTextState().setRenderingMode(mode.intValue());
        }
    }
    Merci d'avance.

  2. #2
    Rédacteur/Modérateur
    Avatar de andry.aime
    Homme Profil pro
    Inscrit en
    Septembre 2007
    Messages
    8 391
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Ile Maurice

    Informations forums :
    Inscription : Septembre 2007
    Messages : 8 391
    Points : 15 059
    Points
    15 059
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    Test1 tes= new Test1();
            CreatePdf(src); // CreatePdf est une méthode static donc tu peux l'appeler directement
    tes.process(tonPDFOperator, tonListCOSBase); // Tu dois passer par l'instance tes pour appeler la méthode process
    A+.

  3. #3
    Membre à l'essai
    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2013
    Messages
    16
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Liban

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juin 2013
    Messages : 16
    Points : 13
    Points
    13
    Par défaut
    D'abord merci beaucoup pour ta réponse. Absoluement ouais, j'ai fait comme ca aussi:
    tes.process("Tj", arguments); mais qu'est ce que je dois mettre dans arguments? est ce que tu as travaillé avant sur cet outil ?

    merci encore,

  4. #4
    Rédacteur/Modérateur
    Avatar de andry.aime
    Homme Profil pro
    Inscrit en
    Septembre 2007
    Messages
    8 391
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Ile Maurice

    Informations forums :
    Inscription : Septembre 2007
    Messages : 8 391
    Points : 15 059
    Points
    15 059
    Par défaut
    Re,

    Je crois que tu as fait une mauvaise conception en mettant tous les attributs static .
    J'ai jamais utilisé PDFBox mais tu dois passer un instance de PDFOperator (une variable de type PDFOperator) en premièr paramètre et une List<COSBase> en second.

    A+.

  5. #5
    Membre à l'essai
    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2013
    Messages
    16
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Liban

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juin 2013
    Messages : 16
    Points : 13
    Points
    13
    Par défaut
    J'ai utilisé content.appendRawCommands("3 Tr") à la place de process et ca marche bien!
    Ma question est résolue

    Bien à toi,

  6. #6
    Membre à l'essai
    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2013
    Messages
    16
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Liban

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juin 2013
    Messages : 16
    Points : 13
    Points
    13
    Par défaut
    Donc c'est le code final qui donne un text rendering mode invisible

    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
    public class Test1 extends OperatorProcessor{
     
        private static final String src="...";
        private static PDFStreamEngine pp;
        private static PDPageContentStream content;
        private static PDType1Font font; 
        public static void CreatePdf(String src) throws IOException, COSVisitorException{
        PDRectangle rec= new PDRectangle(400,400);
        PDDocument document= null;
        document = new PDDocument();
        PDPage page = new PDPage(rec);
        document.addPage(page);
        PDDocumentInformation info=document.getDocumentInformation();
        info.setAuthor("PdfBox");
        info.setCreator("Pdf");
        info.setSubject("Stéganographie");
        info.setTitle("Stéganographie dans les documents PDF");
        info.setKeywords("Stéganographie, pdf");
        content= new PDPageContentStream(document, page);
        font= PDType1Font.HELVETICA;
        String texte="hello";
        content.beginText();
        content.setFont(font, 12);
        content.moveTextPositionByAmount(15, 385);   
        content.appendRawCommands("1 Tr");
        content.drawString(texte);
        content.endText();
        content.close();
        document.save("doc.pdf");
        document.close();       
        }
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) throws IOException, COSVisitorException {
            // TODO code application logic here   
            Test1 tes= new Test1();
            tes.CreatePdf(src);
        }

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Extraire le texte d'un pdf avec PdfBox en C#
    Par nadabb dans le forum C#
    Réponses: 10
    Dernier message: 28/05/2009, 21h00
  2. Convertir un texte en OEM avec Notepad++
    Par Furius dans le forum Autres Logiciels
    Réponses: 17
    Dernier message: 17/10/2005, 13h18
  3. [LG] Ecrire du texte en mode graphique
    Par maind5or dans le forum Langage
    Réponses: 2
    Dernier message: 05/08/2005, 12h55
  4. Texte en transparence avec TextOut
    Par TigreRouge dans le forum MFC
    Réponses: 2
    Dernier message: 06/06/2005, 22h57
  5. Insertion d'un texte en mode graphique
    Par Grinta dans le forum Assembleur
    Réponses: 1
    Dernier message: 13/05/2005, 06h50

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