• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

office_preview: java office在线预览 使用 openoffice 基于SpringBoot2.2.2版本 ...

原作者: [db:作者] 来自: 网络 收藏 邀请

Getting Started

Reference Documentation

For further reference, please consider the following sections:

public class DocumentUtils {    /**     * 使用 JODConverter 将 Office 文档转换成 PDF 文件     *     * @param inFilePath  Office 文档路径     * @param outFilePath 生成的 PDF 文件路径     * @throws IOException     */    public static void convertOfficeDocumentToPDF(String inFilePath, String outFilePath)        /**     * 使用 JODConverter 将 Office 文档输入流转换成 PDF 输出流     *     * @param inputStream  输入流     * @param inputFormat  输入流的文档格式     * @param outputStream 输出流     * @param outputFormat 输出流的文档格式     * @throws IOException     */    public static void convert(InputStream inputStream, DocumentFormat inputFormat, OutputStream outputStream, DocumentFormat outputFormat)        }
    final DocumentFormat pdf = new DocumentFormat("Portable Document Format", "application/pdf", "pdf");    pdf.setExportFilter(DocumentFamily.DRAWING, "draw_pdf_Export");    pdf.setExportFilter(DocumentFamily.PRESENTATION, "impress_pdf_Export");    pdf.setExportFilter(DocumentFamily.SPREADSHEET, "calc_pdf_Export");    pdf.setExportFilter(DocumentFamily.TEXT, "writer_pdf_Export");    final DocumentFormat xls = new DocumentFormat("Microsoft Excel", DocumentFamily.SPREADSHEET, "application/vnd.ms-excel", "xls");    xls.setExportFilter(DocumentFamily.SPREADSHEET, "MS Excel 97");    final DocumentFormat xlsx = new DocumentFormat("Microsoft Excel 2007 XML", DocumentFamily.SPREADSHEET, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "xlsx");    xlsx.setExportFilter(DocumentFamily.SPREADSHEET, "MS Excel 2007");    final DocumentFormat ppt = new DocumentFormat("Microsoft PowerPoint", DocumentFamily.PRESENTATION, "application/vnd.ms-powerpoint", "ppt");    ppt.setExportFilter(DocumentFamily.PRESENTATION, "MS PowerPoint 97");    final DocumentFormat pptx = new DocumentFormat("Microsoft PowerPoint 2007 XML", DocumentFamily.PRESENTATION, "application/vnd.openxmlformats-officedocument.presentationml.presentation", "pptx");    pptx.setExportFilter(DocumentFamily.PRESENTATION, "MS PowerPoint 2007");    final DocumentFormat doc = new DocumentFormat("Microsoft Word", DocumentFamily.TEXT, "application/msword", "doc");    doc.setExportFilter(DocumentFamily.TEXT, "MS Word 97");    final DocumentFormat docx = new DocumentFormat("Microsoft Word 2007 XML", DocumentFamily.TEXT, "application/vnd.openxmlformats-officedocument.wordprocessingml.document", "docx");    docx.setExportFilter(DocumentFamily.TEXT, "MS Word 2007");    BufferedInputStream bis = null;    try {        //获取远程服务器端文件输入流;        bis = new BufferedInputStream(urlconn.getInputStream());        DocumentFormat autoDoc = xls;        System.out.println("file type: " + urlconn.getContentType());        switch (urlconn.getContentType()) {            case "application/vnd.ms-excel":                autoDoc = xls;                break;            case "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":                autoDoc = xlsx;                break;            case "application/vnd.ms-powerpoint":                autoDoc = ppt;                break;            case "application/vnd.openxmlformats-officedocument.presentationml.presentation":                autoDoc = pptx;                break;            case "application/msword":                autoDoc = doc;                break;            case "application/vnd.openxmlformats-officedocument.wordprocessingml.document":                autoDoc = docx;                break;        }        OutputStream os = response.getOutputStream();        DocumentUtils.convert(bis, autoDoc, os, pdf);

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap