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 :

Probleme avec fop 0.93


Sujet :

Documents Java

  1. #1
    Futur Membre du Club
    Inscrit en
    Juillet 2007
    Messages
    9
    Détails du profil
    Informations forums :
    Inscription : Juillet 2007
    Messages : 9
    Points : 8
    Points
    8
    Par défaut Probleme avec fop 0.93
    j'essaie de creer un pdf avec fop version 0.93.
    mon code est le suivant:

    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
    //		  Step 1: Construct a FopFactory
    //		  (reuse if you plan to render multiple documents!)
    		 System.out.println("step 1");
     
     
    //		  Step 2: Set up output stream.
    //		  Note: Using BufferedOutputStream for performance reasons (helpful with FileOutputStreams).
    		 System.out.println("step 2");
    		 String file_name="C:\\Users\\fichier.pdf";
    		 OutputStream out1 = new BufferedOutputStream(new FileOutputStream(file_name));
    		 request.setAttribute("fichier",fichier);
     
    		   // Step 3: Construct fop with desired output format
    		 System.out.println("step 3");
    		 FopFactory fopFactory = FopFactory.newInstance();
    		   Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, out1);
     
    		   // Step 4: Setup JAXP using identity transformer
    		   System.out.println("step 4");
    		   TransformerFactory factory = TransformerFactory.newInstance();
    		   Transformer transformer1 = factory.newTransformer(); // identity transformer
     
    		   // Step 5: Setup input and output for XSLT transformation 
    		   // Setup input stream
    		   System.out.println("step 5");
    		   String chaine=out.toString();
    		   //StringReader src = new StringReader(chaine);
    		   //InputSource source=new InputSource(src);
    		   Source src = new StreamSource(chaine);
     
    		   // Resulting SAX events (the generated FO) must be piped through to FOP
    		   System.out.println("step 6");
    		   Result res = new SAXResult(fop.getDefaultHandler());
     
    		   System.out.println("step 61");         
    		   // Step 6: Start XSLT transformation and FOP processing
    		   transformer1.transform(src,res);
    		   System.out.println("fin de transformation");}


    lorrsque je compile j'ai l'erreur suivante g bo chercher je ne trouve pas d ou ca vient:

    java.net.MalformedURLException: no protocol:

  2. #2
    Futur Membre du Club
    Profil pro
    Inscrit en
    Juin 2007
    Messages
    5
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2007
    Messages : 5
    Points : 6
    Points
    6
    Par défaut
    Salut

    j'ai essayé ton code chez moi, mais n'ayant pas de fichier xsl-fo, je n'arrive pas à reproduire ton erreur.
    Si j'ai bien compris ton programme, tu souhaites créer un pdf à partir d'un fichier xsl-fo? (ou bien depuis un fichier DocBook?)

    Peux-tu préciser un petit peu ton objectif?

    Cependant, ce qui est sur, c'est que les fichiers que tu spécifie via une url doivent exister (je crois que même le fichier de sortie pdf doit déjà exister).
    De plus, je crois que les URL, même sous windows, s'écrivent avec des '/', et non des '\'.
    Essaye ton code avec "C:/Users/fichier.pdf".

    Tiens moi au courant. J'utilise un code similaire au tiens pour convertir du Docbook en pdf, et ça marche très bien.

    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
     
    public void convertXML2PDF(File filexml, File filexslt, File filepdf)
    	throws IOException, FOPException, TransformerException {
    //		Step 1: Construct a FopFactory
    //		(reuse if you plan to render multiple documents!)
    		FopFactory fopFactory = FopFactory.newInstance();
     
    //		Step 2: Set up output stream.
    //		Note: Using BufferedOutputStream for performance reasons (helpful with FileOutputStreams).
    		OutputStream out = new BufferedOutputStream(new FileOutputStream(filepdf));
     
    		try {
    			// Step 3: Construct fop with desired output format
    			Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, out);
     
    			// Step 4: Setup JAXP using identity transformer
    			TransformerFactory factory = TransformerFactory.newInstance();
    			Source xslt = new StreamSource(filexslt);
    			Transformer transformer = factory.newTransformer(xslt);
     
    //			Transformer transformer = factory.newTransformer(); // identity transformer
     
    			// Step 5: Setup input and output for XSLT transformation 
    			// Setup input stream
    //			File temp = new File(filexml);
    			Source src = new StreamSource(filexml);
     
    			// Resulting SAX events (the generated FO) must be piped through to FOP
    			Result res = new SAXResult(fop.getDefaultHandler());
     
    			// Step 6: Start XSLT transformation and FOP processing
    			transformer.transform(src, res);
     
    		} finally {
    			//Clean-up
    			out.close();
    		}
    	}

Discussions similaires

  1. Probleme font avec FOP !
    Par tarekos dans le forum XSL/XSLT/XPATH
    Réponses: 24
    Dernier message: 22/08/2008, 17h01
  2. [XSL-FO]Probleme avec FOP
    Par clairepar dans le forum XSL/XSLT/XPATH
    Réponses: 3
    Dernier message: 26/02/2008, 21h54
  3. probleme avec le trio xml/xsl/fop
    Par snetechen dans le forum Format d'échange (XML, JSON...)
    Réponses: 9
    Dernier message: 30/04/2007, 07h37
  4. Probleme avec fseek
    Par Bjorn dans le forum C
    Réponses: 5
    Dernier message: 04/08/2002, 07h17
  5. [Kylix] probleme avec un imagelist
    Par NicoLinux dans le forum EDI
    Réponses: 4
    Dernier message: 08/06/2002, 23h06

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