Web Services 编写Web服务以将文档转换为PDF

jc3wubiy  于 2022-11-15  发布在  其他
关注(0)|答案(5)|浏览(145)

是否可以编写一个REST风格的Web服务,以便从客户端接收文件,将这些文件转换为PDF文件,然后将结果发送回客户端?
任何有关该主题的信息都将是有帮助的。

x3naxklr

x3naxklr1#

x-to-PDF转换和PDF生成:

休息时间:

  • JAX-RS-用于REST的Java API。
7fyelxc5

7fyelxc52#

几年前,我做了一个简单但强大的类来转换HTML到PDF.真的很有用:

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);                
    }   

}

用法:

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

所有文件位于:https://dl.getdropbox.com/u/15403/Html2PDF.zip

x6h2sr28

x6h2sr283#

我从你自己的评论中看到,你对从Java将Office文件转换为PDF很感兴趣。
也许是一个无耻的产品插件,因为我自己也在这个产品上工作过,但是看看这个web service for converting Common document formats to PDF。Java示例代码包含在这个帖子中。

rmbxnbpk

rmbxnbpk4#

您可能需要提供更多有关您希望转换为PDF的文件类型的信息,因为这将决定转换过程的底层技术。除此之外,您只有一个文档传输系统要在您的Web服务中实现,它独立于转换过程。Docmosis可以嵌入服务器端,它可以提供OpenOffice中可用的所有文档转换过滤器。还允许您填充和操作文档。

g6baxovj

g6baxovj5#

我尝试了一些用于将.xls* 转换为.pdf的库:
aspose-cell-良好结果,需要付费
spire.xls.free - 有时会给予不正确的.pdf,是免费的
itextpdf -最糟糕的是,是免费的
libreoffice -使用libreoffice转换,需要windows服务器-是免费的
https://github.com/fedor83/xlsToPdfConverter

相关问题