views:

302

answers:

4

Is it possible to write a RESTful web service that will accept files from a client, convert those files to PDF files and then will send the result back to the client?

Any information on the topic would be helpful.

+4  A: 

x-to-PDF conversion and PDF generation:

REST:

  • JAX-RS - the Java API for REST.
Bozho
while generating pdf from doc using IText, it adds some junk chars in the start and end of the pdf file.I have posted it as a separate question as below.http://stackoverflow.com/questions/2145194/while-generating-pdf-from-doc-using-itext-it-adds-some-junk-chars-in-the-startSee it if you can guide me to solve this issue
M Ismail
+2  A: 

Some years ago i've made a simple but poerfull class to convert HTML to PDF. Really usefull:

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.OutputStream;

import org.w3c.dom.Document;
import org.w3c.tidy.Tidy;
import org.xhtmlrenderer.pdf.ITextRenderer;

import com.lowagie.text.DocumentException;

/**
 * @Autor Eder Baum
 */
public class Html2Pdf {

    public static void convert(String input, OutputStream out) throws DocumentException{
        convert(new ByteArrayInputStream(input.getBytes()), out);
    }

    public static void convert(InputStream input, OutputStream out) throws DocumentException{
        Tidy tidy = new Tidy();         
        Document doc = tidy.parseDOM(input, null);
        ITextRenderer renderer = new ITextRenderer();
        renderer.setDocument(doc, null);
        renderer.layout();       
        renderer.createPDF(out);                
    }   

}

Usage:

OutputStream os = new FileOutputStream("C:\\hello.pdf");;
Html2Pdf.convert("<h1 style=\"color:red\">Hello PDF</h1>", os);         
os.close();

All Files here: https://dl.getdropbox.com/u/15403/Html2PDF.zip

EderBaum
A: 

You might want to supply more information about the types of files you are hoping to convert to PDF since that will determine the underlying technolgy for the conversion process. Apart from that you have only a document transport system to implement in your web service which is independent of the conversion process. Docmosis can be embedded server side which can provide all the document conversion filters available in OpenOffice, but also allows you to populate and manipulate documents.

jowierun
A: 

I see from your own comment that you are interested in converting Office files to PDF from Java.

A shameless product plug perhaps, as I have worked on this product myself, but check out this web service for converting Common document formats to PDF. Java sample code is included in the post.

Muhimbi