cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Geoff Howard <ghow...@crosswalk.com>
Subject RE: Can cocoon write pdf to a file?
Date Fri, 16 Aug 2002 14:11:41 GMT
> will this code get .pdf file over HTTP? 
> if yes, then wouldn't it be more efficient if instead of that, you somehow

> directly write on the hard disk without loading a Web server?

Yes! you want SourceWritingTransformer from Cocoon 2.1 dev.  There is a 
parameter to tell it how to serialize the output.  It writes to a file 
on the local hard drive.

Geoff


> -----Original Message----- 
> From: Terry Anderson [mailto:tanderson@highergear.com] 
> Sent: Friday, August 16, 2002 9:44 AM 
> To: cocoon-users@xml.apache.org 
> Subject: RE: Can cocoon write pdf to a file? 
> 
> 
> All, 
> 
> Sorry, mentioned the wrong transformer earlier. Used stream generator, 
> posted xml, saved to file. See code below. 
> 
> JAVA CLASS: 
>             URL url = new URL("http://path/xml2pdf.pdf"); 
>             HttpURLConnection httpConn = null; 
>             try { 
>                 httpConn = (HttpURLConnection)url.openConnection(); 
>                 httpConn.setDoInput(true); 
>                 httpConn.setDoOutput(true); 
>                 httpConn.setRequestMethod("POST"); 
>                 httpConn.setUseCaches(false); 
>                 httpConn.setDefaultUseCaches(false); 
>  
> httpConn.setRequestProperty("content-type","application/x-www- 
> form-urlen 
> coded"); 
>  
> httpConn.setRequestProperty("content-length",String.valueOf(xm 
> l_os.size( 
> ))); 
>                 PrintWriter pw = new 
> PrintWriter(httpConn.getOutputStream()); 
>                 String content = "Foo=" + URLEncoder.encode(new 
> String(xml_os.toByteArray()),"UTF-8"); 
>                 pw.println(content); 
>                 pw.close(); 
> 
>                 InputStream is = httpConn.getInputStream(); 
>                 BufferedInputStream bis = new BufferedInputStream(is); 
>                 byte[] buff = new byte[512]; 
>                 ByteArrayOutputStream bos = new 
> ByteArrayOutputStream(); 
>                 String line = null; 
>                 int len = 0; 
>                 while( (len=bis.read(buff)) != -1) { 
>                     bos.write(buff, 0, len); 
>                 } 
>                 bis.close(); 
>                 String fileName = "out.pdf"; 
>                 FileOutputStream fos = null; 
>                 File file = null; 
>                 try { 
>                     file = new File(fileName); 
>                     fos = new FileOutputStream(file); 
>                     fos.write(bos.toByteArray()); 
>                 } catch (IOException ioe) { 
>                     System.out.println("Exception Caught: 
> Creating .pdf 
> File"); 
>                     ioe.printStackTrace(); 
>                 } finally { 
>                     if (fos!=null) { 
>                         fos.close(); 
>                     } 
>                 } 
>                 System.out.println("***** FILE CREATED: "+fileName+" 
> *****"); 
> 
> SITEMAP.XMAP : 
>       <map:match pattern="*.pdf"> 
>         <map:generate type="stream"> 
>             <map:parameter name="form-name" value="Foo"/> 
>         </map:generate> 
>         <map:transform type="xslt" src="doc2pdf.xsl"/> 
>         <map:serialize type="fo2pdf"/> 
>       </map:match> 
> 
> 
> -----Original Message----- 
> From: Derek Hohls [mailto:DHohls@csir.co.za] 
> Sent: Friday, August 16, 2002 1:50 AM 
> To: cocoon-users@xml.apache.org 
> Subject: RE: Can cocoon write pdf to a file? 
> 
> 
> Can you supply a link to this discussion/anwer? 
> 
> >>> tanderson@highergear.com 16/08/2002 12:20:57 >>> 
> This has been answered in the archives. 
> I used the pdf transformer and saved the output stream to a file. 
>  
> TA 
> -----Original Message----- 
> From: Geoff Howard [mailto:ghoward@crosswalk.com] 
> Sent: Thursday, August 15, 2002 2:07 PM 
> To: 'cocoon-users@xml.apache.org' 
> Subject: RE: Can cocoon write pdf to a file? 
> 
> 
> you should check the archives - i'm pretty sure this has been 
> answered a 
> lot.  Think you'll want SourceWritingTransformer from Cocoon 2.1 dev 
> (cvs check out from HEAD) 
>  
> Geoff 
> -----Original Message----- 
> From: kyle koss [mailto:kkoss@xperient.net] 
> Sent: Thursday, August 15, 2002 1:54 PM 
> To: cocoon-users@xml.apache.org 
> Subject: Can cocoon write pdf to a file? 
> 
> 
> Is it possible for Cocoon to do an XML+XSL -> PDF transformation, but 
> instead of serving the PDF into the browser, writing it to a file? 
>  
> What I would like to do is, take information entered into a form on a 
> jsp page, turn it into an XML file, and then apply my XSL to it to 
> produce a PDF which is then stored to disk on the server. 
>  
> Can this be done using Cocoon, or would it be easier to just use FOP 
> embedded in a servlet? If it can be done, what do I have to do? 
>  
> Regards, Kyle Koss 
> 
> --------------------------------------------------------------------- 
> Please check that your question  has not already been answered in the 
> FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html> 
> 
> To unsubscribe, e-mail:     <cocoon-users-unsubscribe@xml.apache.org> 
> For additional commands, e-mail:   <cocoon-users-help@xml.apache.org> 
> 
> 
> 
> 
> 
> 
> --------------------------------------------------------------------- 
> Please check that your question  has not already been answered in the 
> FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html> 
> 
> To unsubscribe, e-mail:     <cocoon-users-unsubscribe@xml.apache.org> 
> For additional commands, e-mail:   <cocoon-users-help@xml.apache.org> 
> 

---------------------------------------------------------------------
Please check that your question  has not already been answered in the
FAQ before posting.     <http://xml.apache.org/cocoon/faq/index.html>

To unsubscribe, e-mail:     <cocoon-users-unsubscribe@xml.apache.org>
For additional commands, e-mail:   <cocoon-users-help@xml.apache.org>


Mime
View raw message